util/log: add MESA_LOG_FILE_AUTO to generate log file

if set, creates a file in /tmp folder with mesa_<process_name>_<pid>_XXXXXX.log
logging all errors, warnings, etc., rather than stderr. The XXXXXX will be replaced
with alpha numeric character so for each run of the app a new log file will be
created guaranteed.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39206>
This commit is contained in:
Yogesh Mohan Marimuthu 2026-01-07 22:17:11 +05:30 committed by Marge Bot
parent fa88c65bb8
commit f050e6ea74
2 changed files with 27 additions and 7 deletions

View file

@ -98,6 +98,13 @@ Core Mesa environment variables
specifies a file name for logging all errors, warnings, etc., rather
than stderr
.. envvar:: MESA_LOG_FILE_AUTO
if set, creates a file in /tmp folder with mesa_<process_name>_<pid>_XXXXXX.log
logging all errors, warnings, etc., rather than stderr. The XXXXXX will be replaced
with alpha numeric character so for each run of the app a new log file will be
created guaranteed.
.. envvar:: MESA_LOG_PREFIX
specifies what to to include in the log prefix (linux only) - default is ``tag,level``

View file

@ -144,13 +144,26 @@ mesa_log_init_once(void)
#if !DETECT_OS_WINDOWS
if (__normal_user()) {
const char *log_file = os_get_option("MESA_LOG_FILE");
if (log_file) {
FILE *fp = fopen(log_file, "w");
if (fp) {
mesa_log_file = fp;
mesa_log_control |= MESA_LOG_CONTROL_FILE;
}
FILE *fp = NULL;
if (os_get_option("MESA_LOG_FILE_AUTO")) {
char log_file[512];
int fd;
snprintf(log_file, sizeof(log_file), "/tmp/mesa_%s_%d_XXXXXX.log", util_get_process_name(),
getpid());
fd = mkstemps(log_file, 4);
if (fd >= 0)
fp = fdopen(fd, "w");
} else {
const char *log_file = os_get_option("MESA_LOG_FILE");
if (log_file)
fp = fopen(log_file, "w");
}
if (fp) {
mesa_log_file = fp;
mesa_log_control |= MESA_LOG_CONTROL_FILE;
}
}
#endif