diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2007-06-06 10:22:33 +0000 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2007-06-06 10:22:33 +0000 |
commit | 01bcb8190fec2b5484668a5b5bdad73914741348 (patch) | |
tree | 0fcaa4d3cad805402f6f657a711a4c78e0aac9e4 /src/debug.c | |
parent | db837df6bce80e134dd6c93824d1c0ff53f75ad6 (diff) | |
download | telepathy-salut-01bcb8190fec2b5484668a5b5bdad73914741348.tar.gz |
add support for SALUT_LOGFILE env variable to log output to a file
20070606102233-7fe3f-94ed9d813bc24e4630ecb141e14708132cf7a8cd.gz
Diffstat (limited to 'src/debug.c')
-rw-r--r-- | src/debug.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/debug.c b/src/debug.c index 43f4bfa2..c105fde4 100644 --- a/src/debug.c +++ b/src/debug.c @@ -1,12 +1,51 @@ #include <stdarg.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> #include <glib.h> +#include <glib/gstdio.h> #include <telepathy-glib/debug.h> #include "debug.h" +void +debug_set_log_file_from_env (void) +{ + const gchar *output_file; + int out; + + output_file = g_getenv ("SALUT_LOGFILE"); + if (output_file == NULL) + return; + + out = g_open (output_file, O_WRONLY | O_CREAT, 0644); + if (out == -1) + { + g_warning ("Can't open logfile '%s': %s", output_file, + g_strerror (errno)); + return; + } + + if (dup2 (out, STDOUT_FILENO) == -1) + { + g_warning ("Error when duplicating stdout file descriptor: %s", + g_strerror (errno)); + return; + } + + if (dup2 (out, STDERR_FILENO) == -1) + { + g_warning ("Error when duplicating stderr file descriptor: %s", + g_strerror (errno)); + return; + } +} + #ifdef ENABLE_DEBUG static DebugFlags flags = 0; |