diff --git a/src/vrend_debug.c b/src/vrend_debug.c index bd9b7cc..fc4ed30 100644 --- a/src/vrend_debug.c +++ b/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;