search: Move close button to the right edge (see #665945)
[anjuta.git] / libanjuta / anjuta-debug.c
blobfaa93bb5793b713eb477bcc4347bb49eb830b12a
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 anjuta-debug.c
4 Copyright (C) 2008 Sébastien Granjoux <seb.sfo@free.fr>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "anjuta-debug.h"
23 #include <glib.h>
25 #include <string.h>
27 static gchar **anjuta_log_modules = NULL;
29 static void
30 anjuta_log_handler (const char *log_domain,
31 GLogLevelFlags log_level,
32 const char *message,
33 gpointer user_data)
36 if (log_level & G_LOG_LEVEL_DEBUG)
38 /* Filter only debugging messages */
39 gint i;
40 const gchar *domain;
42 /* Do not display anything if anjuta_log_modules is empty
43 * (happens only in non debugging mode) */
44 if (anjuta_log_modules == NULL) return;
46 /* log_domain can be NULL*/
47 domain = (log_domain == NULL) || (*log_domain == '\0') ? "NULL" : log_domain;
49 for (i = 0; anjuta_log_modules[i] != NULL; i++)
51 if (strcmp(domain, anjuta_log_modules[i]) == 0)
53 /* Display message */
54 g_log_default_handler (log_domain, log_level, message, user_data);
55 return;
59 return;
62 g_log_default_handler (log_domain, log_level, message, user_data);
65 /**
66 * anjuta_debug_init :
68 * Initialize filtering of debug messages.
70 void
71 anjuta_debug_init (void)
73 const gchar *log;
74 gboolean all = FALSE;
76 log = g_getenv ("ANJUTA_LOG_DOMAINS");
77 if (log != NULL)
79 anjuta_log_modules = g_strsplit_set (log, ": ", -1);
81 if (anjuta_log_modules != NULL)
83 gint i;
85 for (i = 0; anjuta_log_modules[i] != NULL; i++)
87 if (strcmp("all", anjuta_log_modules[i]) == 0)
89 all = TRUE;
90 break;
96 #ifdef DEBUG
97 if ((anjuta_log_modules != NULL) && (anjuta_log_modules[0] != NULL) && !all)
99 /* Display selected message in debugging mode if environment
100 * variable is no set to all */
101 #else
102 if (!all)
104 /* Display selected message in non debugging mode if the
105 * environment variable doesn't exist or if not set to all */
106 #endif
107 g_log_set_default_handler (anjuta_log_handler, NULL);