diff --git a/src/mesa/main/debug_output.c b/src/mesa/main/debug_output.c index bee71950dea..cf61355d035 100644 --- a/src/mesa/main/debug_output.c +++ b/src/mesa/main/debug_output.c @@ -34,6 +34,7 @@ #include "version.h" #include "util/hash_table.h" #include "util/list.h" +#include "util/log.h" #include "util/u_memory.h" #include "api_exec_decl.h" diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c index 36e70405965..571918cb93c 100644 --- a/src/mesa/main/errors.c +++ b/src/mesa/main/errors.c @@ -39,33 +39,6 @@ #include "util/log.h" #include "api_exec_decl.h" -static void -output_if_debug(enum mesa_log_level level, const char *outputString) -{ - static int debug = -1; - - /* Init the local 'debug' var once. - * Note: the _mesa_init_debug() function should have been called - * by now so MESA_DEBUG_FLAGS will be initialized. - */ - if (debug == -1) { -#ifndef NDEBUG - /* in debug builds, print messages unless MESA_DEBUG="silent" */ - if (MESA_DEBUG_FLAGS & DEBUG_SILENT) - debug = 0; - else - debug = 1; -#else - const char *env = getenv("MESA_DEBUG"); - debug = env && strstr(env, "silent") == NULL; -#endif - } - - /* Now only print the string if we're required to do so. */ - if (debug) - mesa_log(level, "Mesa", "%s", outputString); -} - /** * When a new type of error is recorded, print a message describing * previous errors which were accumulated. @@ -80,7 +53,7 @@ flush_delayed_errors( struct gl_context *ctx ) ctx->ErrorDebugCount, _mesa_enum_to_string(ctx->ErrorValue)); - output_if_debug(MESA_LOG_ERROR, s); + mesa_log_if_debug(MESA_LOG_ERROR, s); ctx->ErrorDebugCount = 0; } @@ -106,7 +79,7 @@ _mesa_warning( struct gl_context *ctx, const char *fmtString, ... ) if (ctx) flush_delayed_errors( ctx ); - output_if_debug(MESA_LOG_WARN, str); + mesa_log_if_debug(MESA_LOG_WARN, str); } @@ -306,7 +279,7 @@ _mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... ) /* Print the error to stderr if needed. */ if (do_output) { - output_if_debug(MESA_LOG_ERROR, s2); + mesa_log_if_debug(MESA_LOG_ERROR, s2); } /* Log the error via ARB_debug_output if needed.*/ @@ -344,30 +317,12 @@ _mesa_debug( const struct gl_context *ctx, const char *fmtString, ... ) va_start(args, fmtString); vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args); va_end(args); - output_if_debug(MESA_LOG_DEBUG, s); + mesa_log_if_debug(MESA_LOG_DEBUG, s); #endif /* !NDEBUG */ (void) ctx; (void) fmtString; } - -void -_mesa_log(const char *fmtString, ...) -{ - char s[MAX_DEBUG_MESSAGE_LENGTH]; - va_list args; - va_start(args, fmtString); - vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args); - va_end(args); - output_if_debug(MESA_LOG_INFO, s); -} - -void -_mesa_log_direct(const char *string) -{ - output_if_debug(MESA_LOG_INFO, string); -} - /** * Report debug information from the shader compiler via GL_ARB_debug_output. * diff --git a/src/mesa/main/errors.h b/src/mesa/main/errors.h index b859625c447..f921b8e27b5 100644 --- a/src/mesa/main/errors.h +++ b/src/mesa/main/errors.h @@ -63,12 +63,6 @@ _mesa_error_no_memory(const char *caller); extern void _mesa_debug( const struct gl_context *ctx, const char *fmtString, ... ) PRINTFLIKE(2, 3); -extern void -_mesa_log(const char *fmtString, ...) PRINTFLIKE(1, 2); - -extern void -_mesa_log_direct(const char *string); - void _mesa_shader_debug(struct gl_context *ctx, GLenum type, GLuint *id, diff --git a/src/util/log.c b/src/util/log.c index 41db2014f4c..ecd84447f34 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -119,6 +119,34 @@ mesa_log_init(void) call_once(&once, mesa_log_init_once); } +void +mesa_log_if_debug(enum mesa_log_level level, const char *outputString) +{ + static int debug = -1; + + /* Init the local 'debug' var once. */ + if (debug == -1) { + const char *env = getenv("MESA_DEBUG"); + bool silent = env && strstr(env, "silent") != NULL; +#ifndef NDEBUG + /* in debug builds, print messages unless MESA_DEBUG="silent" */ + if (silent) + debug = 0; + else + debug = 1; +#else + /* in release builds, print messages if any MESA_DEBUG value other than + * MESA_DEBUG="silent" is set + */ + debug = env && !silent; +#endif + } + + /* Now only print the string if we're required to do so. */ + if (debug) + mesa_log(level, "Mesa", "%s", outputString); +} + static inline const char * level_to_str(enum mesa_log_level l) { @@ -387,6 +415,23 @@ mesa_log_v(enum mesa_log_level level, const char *tag, const char *format, } } +void +_mesa_log(const char *fmtString, ...) +{ + char s[MAX_LOG_MESSAGE_LENGTH]; + va_list args; + va_start(args, fmtString); + vsnprintf(s, MAX_LOG_MESSAGE_LENGTH, fmtString, args); + va_end(args); + mesa_log_if_debug(MESA_LOG_INFO, s); +} + +void +_mesa_log_direct(const char *string) +{ + mesa_log_if_debug(MESA_LOG_INFO, string); +} + struct log_stream * _mesa_log_stream_create(enum mesa_log_level level, const char *tag) { diff --git a/src/util/log.h b/src/util/log.h index b9d062dc3d7..7bcce3d61e0 100644 --- a/src/util/log.h +++ b/src/util/log.h @@ -44,6 +44,8 @@ enum mesa_log_level { MESA_LOG_DEBUG, }; +#define MAX_LOG_MESSAGE_LENGTH 4096 + FILE * mesa_log_get_file(void); @@ -54,6 +56,15 @@ void mesa_log_v(enum mesa_log_level, const char *tag, const char *format, va_list va); +void +_mesa_log(const char *fmtString, ...) PRINTFLIKE(1, 2); + +void +_mesa_log_direct(const char *string); + +void +mesa_log_if_debug(enum mesa_log_level level, const char *outputString); + #define mesa_loge(fmt, ...) mesa_log(MESA_LOG_ERROR, (MESA_LOG_TAG), (fmt), ##__VA_ARGS__) #define mesa_logw(fmt, ...) mesa_log(MESA_LOG_WARN, (MESA_LOG_TAG), (fmt), ##__VA_ARGS__) #define mesa_logi(fmt, ...) mesa_log(MESA_LOG_INFO, (MESA_LOG_TAG), (fmt), ##__VA_ARGS__)