1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2006-2007 Imendio AB
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Authors: Richard Hult <richard@imendio.com>
28 #include <sys/types.h>
34 #include <glib/gprintf.h>
35 #include <glib/gstdio.h>
37 #include <telepathy-glib/debug.h>
39 /* Set EMPATHY_DEBUG to a colon/comma/space separated list of domains, or "all"
40 * to get all debug output.
43 #include "empathy-debug.h"
45 static gchar **debug_strv;
46 static gboolean all_domains = FALSE;
51 static gboolean inited = FALSE;
57 env = g_getenv ("EMPATHY_DEBUG");
58 tp_debug_set_flags (env);
61 debug_strv = g_strsplit_set (env, ":, ", 0);
66 for (i = 0; debug_strv && debug_strv[i]; i++) {
67 if (strcmp ("all", debug_strv[i]) == 0) {
77 empathy_debug_impl (const gchar *domain, const gchar *msg, ...)
81 g_return_if_fail (domain != NULL);
82 g_return_if_fail (msg != NULL);
86 for (i = 0; debug_strv && debug_strv[i]; i++) {
87 if (all_domains || strcmp (domain, debug_strv[i]) == 0) {
90 g_print ("%s: ", domain);
93 g_vprintf (msg, args);
103 empathy_debug_set_log_file_from_env (void)
105 const gchar *output_file;
108 output_file = g_getenv ("EMPATHY_LOGFILE");
109 if (output_file == NULL) {
113 out = g_open (output_file, O_WRONLY | O_CREAT, 0644);
115 g_warning ("Can't open logfile '%s': %s", output_file,
120 if (dup2 (out, STDOUT_FILENO) == -1) {
121 g_warning ("Error when duplicating stdout file descriptor: %s",
126 if (dup2 (out, STDERR_FILENO) == -1) {
127 g_warning ("Error when duplicating stderr file descriptor: %s",