diff --git a/docs/envvars.rst b/docs/envvars.rst index 22123800ce7..ae479120e92 100644 --- a/docs/envvars.rst +++ b/docs/envvars.rst @@ -98,6 +98,10 @@ Core Mesa environment variables specifies a file name for logging all errors, warnings, etc., rather than stderr +.. envvar:: MESA_LOG_PREFIX + + specifies what to to include in the log prefix (linux only) - default is ``tag,level`` + .. envvar:: MESA_EXTENSION_OVERRIDE can be used to enable/disable extensions. A value such as diff --git a/src/util/log.c b/src/util/log.c index fa1b9506696..4022b6b556e 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -55,6 +55,12 @@ enum mesa_log_control { MESA_LOG_CONTROL_WAIT = 1 << 8, }; +enum logger_vasnprintf_affix { + LOGGER_VASNPRINTF_AFFIX_TAG = 1 << 0, + LOGGER_VASNPRINTF_AFFIX_LEVEL = 1 << 1, + LOGGER_VASNPRINTF_AFFIX_NEWLINE = 1 << 2, +}; + static const struct debug_control mesa_log_control_options[] = { /* loggers */ { "null", MESA_LOG_CONTROL_NULL }, @@ -96,6 +102,13 @@ level_from_str(const char *str) static uint32_t mesa_log_control; static FILE *mesa_log_file; static enum mesa_log_level mesa_max_log_level; +static int mesa_log_file_affixes; + +static const struct debug_named_value log_prefix_options[] = { + {"tag", LOGGER_VASNPRINTF_AFFIX_TAG, "include log tag"}, + {"level", LOGGER_VASNPRINTF_AFFIX_LEVEL, "include log level"}, + DEBUG_NAMED_VALUE_END +}; static void mesa_log_init_once(void) @@ -123,6 +136,10 @@ mesa_log_init_once(void) if (log_level != NULL) mesa_max_log_level = level_from_str(log_level); + mesa_log_file_affixes = + debug_get_flags_option("MESA_LOG_PREFIX", log_prefix_options, + LOGGER_VASNPRINTF_AFFIX_TAG | LOGGER_VASNPRINTF_AFFIX_LEVEL); + mesa_log_file = stderr; #if !DETECT_OS_WINDOWS @@ -193,12 +210,6 @@ mesa_log_if_debug(enum mesa_log_level level, const char *outputString) mesa_log(level, "Mesa", "%s", outputString); } -enum logger_vasnprintf_affix { - LOGGER_VASNPRINTF_AFFIX_TAG = 1 << 0, - LOGGER_VASNPRINTF_AFFIX_LEVEL = 1 << 1, - LOGGER_VASNPRINTF_AFFIX_NEWLINE = 1 << 2, -}; - /* Try vsnprintf first and fall back to vasprintf if buf is too small. This * function handles all errors and never fails. */ @@ -281,8 +292,7 @@ logger_file(enum mesa_log_level level, FILE *fp = mesa_log_file; char local_msg[1024]; char *msg = logger_vasnprintf(local_msg, sizeof(local_msg), - LOGGER_VASNPRINTF_AFFIX_TAG | - LOGGER_VASNPRINTF_AFFIX_LEVEL | + mesa_log_file_affixes | LOGGER_VASNPRINTF_AFFIX_NEWLINE, level, tag, format, va);