debug: Add support to log to file.

When VIRGL_LOG_FILE gets set, put log into it. This is similar
with MESA_LOG_FILE. An improvement over MESA_LOG_FILE is that
it supports "%PID%" in file name and will replace it with pid
of the current process.

Signed-off-by: Lepton Wu <lepton@chromium.org>
Reviewed-by: Gert Wollny <gert.wollny@collabora.com>
macos/master
Lepton Wu 5 years ago
parent e8d497f4a1
commit ff43cc76ae
  1. 29
      src/vrend_debug.c

@ -174,7 +174,34 @@ int vrend_debug_can_override(void)
static
void vrend_default_debug_callback(const char *fmt, va_list va)
{
vfprintf(stderr, fmt, va);
static FILE* fp = NULL;
if (NULL == fp) {
const char* log = getenv("VIRGL_LOG_FILE");
if (log) {
char *log_prefix = strdup(log);
char *log_suffix = strstr(log_prefix, "%PID%");
if (log_suffix) {
*log_suffix = 0;
log_suffix += 5;
int len = strlen(log) + 32;
char *name = malloc(len);
snprintf(name, len, "%s%d%s", log_prefix, getpid(), log_suffix);
fp = fopen(name, "a");
free(name);
} else {
fp = fopen(log, "a");
}
free(log_prefix);
if (NULL == fp) {
fprintf(stderr, "Can't open %s\n", log);
fp = stderr;
}
} else {
fp = stderr;
}
}
vfprintf(fp, fmt, va);
fflush(fp);
}
static virgl_debug_callback_type debug_callback = vrend_default_debug_callback;

Loading…
Cancel
Save