From a8a6226a74d81da8c8a6c6766c56a15993d2eb47 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Mon, 9 Jul 2007 18:59:01 +0000 Subject: Add EMPATHY_LOGFILE env variable. Fixes bug #455240 (Guillaume Desmottes). 2007-07-09 Xavier Claessens * src/empathy.c: * libempathy/empathy-debug.c: * libempathy/empathy-debug.h: Add EMPATHY_LOGFILE env variable. Fixes bug #455240 (Guillaume Desmottes). svn path=/trunk/; revision=179 --- ChangeLog | 7 +++++++ libempathy/empathy-debug.c | 37 +++++++++++++++++++++++++++++++++++++ libempathy/empathy-debug.h | 5 ++++- src/empathy.c | 2 ++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0823abdbb..4a5bb445c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-07-09 Xavier Claessens + + * src/empathy.c: + * libempathy/empathy-debug.c: + * libempathy/empathy-debug.h: Add EMPATHY_LOGFILE env variable. Fixes + bug #455240 (Guillaume Desmottes). + 2007-07-09 Xavier Claessens * libempathy-gtk/empathy-account-widget-msn.glade: diff --git a/libempathy/empathy-debug.c b/libempathy/empathy-debug.c index 2f5658499..c3e5d74b0 100644 --- a/libempathy/empathy-debug.c +++ b/libempathy/empathy-debug.c @@ -24,9 +24,15 @@ #include #include +#include +#include +#include +#include +#include #include #include +#include /* Set EMPATHY_DEBUG to a colon/comma/space separated list of domains, or "all" * to get all debug output. @@ -90,3 +96,34 @@ empathy_debug_impl (const gchar *domain, const gchar *msg, ...) } } +void +empathy_debug_set_log_file_from_env (void) +{ + const gchar *output_file; + gint out; + + output_file = g_getenv ("EMPATHY_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; + } +} + diff --git a/libempathy/empathy-debug.h b/libempathy/empathy-debug.h index 19d2aa380..fca53f4bd 100644 --- a/libempathy/empathy-debug.h +++ b/libempathy/empathy-debug.h @@ -45,7 +45,10 @@ G_BEGIN_DECLS # endif #endif -void empathy_debug_impl (const gchar *domain, const gchar *msg, ...); +void empathy_debug_impl (const gchar *domain, + const gchar *msg, + ...); +void empathy_debug_set_log_file_from_env (void); G_END_DECLS diff --git a/src/empathy.c b/src/empathy.c index 416d2134d..9a764cef3 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -167,6 +167,8 @@ main (int argc, char *argv[]) { NULL } }; + empathy_debug_set_log_file_from_env (); + bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); -- cgit v1.2.3