Fix the label int he sidebar
[gmpc.git] / src / Tools / log.c
blob240b3384ac2fd51c7e73e952813f735bc772c673
1 /* Gnome Music Player Client (GMPC)
2 * Copyright (C) 2004-2012 Qball Cow <qball@gmpclient.org>
3 * Project homepage: http://gmpclient.org/
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (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
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <strings.h>
26 #include <glib.h>
27 #include <glib/gstdio.h>
28 #include <libmpd/debug_printf.h>
30 #include "log.h"
32 #define LOG_DOMAIN "Gmpc.Log"
35 static GLogLevelFlags global_log_level = G_LOG_LEVEL_MESSAGE;
37 static void gmpc_log_func(
38 const gchar * log_domain,
39 GLogLevelFlags log_level,
40 const gchar * message,
41 gpointer user_data)
43 if (log_level <= global_log_level)
45 g_log_default_handler(log_domain, log_level, message, user_data);
50 gboolean log_add_filter(
51 const gchar * option_name,
52 const gchar * value,
53 gpointer data,
54 GError ** error)
56 if (value == NULL || value[0] == 0)
58 g_set_error(error, 0, 0, "--log-filter requires a log domain as argument");
59 return FALSE;
62 g_log_set_handler(
63 value,
64 G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
65 g_log_default_handler,
66 NULL);
67 return TRUE;
70 void log_init(void)
73 g_log_set_default_handler(gmpc_log_func, NULL);
77 void log_set_debug_level(int debug_level)
79 /**
80 * Set debug level, options are
81 * 0 = No debug
82 * 1 = Error messages
83 * 2 = Error + Warning messages
84 * 3 = All messages
86 if (debug_level >= 0)
88 if (debug_level == 3)
90 global_log_level = G_LOG_LEVEL_DEBUG;
91 } else if (debug_level == 2)
93 global_log_level = G_LOG_LEVEL_INFO;
95 debug_set_level(debug_level);