summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/os/os_misc.c
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2012-05-22 09:32:50 -0600
committerBrian Paul <brianp@vmware.com>2012-05-25 10:02:21 -0600
commit9c8568743935f0892bb5bd33f5a5210bae53b8d3 (patch)
tree19d299308de55193e05fe5af9c019710abb980c8 /src/gallium/auxiliary/os/os_misc.c
parentab014adaed14a9ca213447dc913d0dce7906be56 (diff)
downloadexternal_mesa3d-9c8568743935f0892bb5bd33f5a5210bae53b8d3.zip
external_mesa3d-9c8568743935f0892bb5bd33f5a5210bae53b8d3.tar.gz
external_mesa3d-9c8568743935f0892bb5bd33f5a5210bae53b8d3.tar.bz2
util: add GALLIUM_LOG_FILE option for logging output to a file
Useful for logging different runs to files and diffing, etc.
Diffstat (limited to 'src/gallium/auxiliary/os/os_misc.c')
-rw-r--r--src/gallium/auxiliary/os/os_misc.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/gallium/auxiliary/os/os_misc.c b/src/gallium/auxiliary/os/os_misc.c
index 5744dd5..447e720 100644
--- a/src/gallium/auxiliary/os/os_misc.c
+++ b/src/gallium/auxiliary/os/os_misc.c
@@ -50,16 +50,35 @@
void
os_log_message(const char *message)
{
+ /* If the GALLIUM_LOG_FILE environment variable is set to a valid filename,
+ * write all messages to that file.
+ */
+ static FILE *fout = NULL;
+
+ if (!fout) {
+ /* one-time init */
+ const char *filename = os_get_option("GALLIUM_LOG_FILE");
+ if (filename)
+ fout = fopen(filename, "w");
+ if (!fout)
+ fout = stderr;
+ }
+
#if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
OutputDebugStringA(message);
if(GetConsoleWindow() && !IsDebuggerPresent()) {
fflush(stdout);
- fputs(message, stderr);
- fflush(stderr);
+ fputs(message, fout);
+ fflush(fout);
+ }
+ else if (fout != stderr) {
+ fputs(message, fout);
+ fflush(fout);
}
#else /* !PIPE_SUBSYSTEM_WINDOWS */
fflush(stdout);
- fputs(message, stderr);
+ fputs(message, fout);
+ fflush(fout);
#endif
}