3
** Login : <ctaf42@gmail.com>
4
** Started on Sat Feb 9 15:54:57 2008 Cedric GESTES
10
** Copyright (C) 2008 Cedric GESTES
11
** This program is free software; you can redistribute it and/or modify
12
** it under the terms of the GNU General Public License as published by
13
** the Free Software Foundation; either version 3 of the License, or
14
** (at your option) any later version.
16
** This program is distributed in the hope that it will be useful,
17
** but WITHOUT ANY WARRANTY; without even the implied warranty of
18
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
** GNU General Public License for more details.
21
** You should have received a copy of the GNU General Public License
22
** along with this program; if not, write to the Free Software
23
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30
#include "cairo-dock-log.h"
32
static char s_iLogColor = '0';
33
static GLogLevelFlags s_gLogLevel = 0;
35
/* # 'default' => "\033[1m", */
37
/* # 'black' => "\033[30m", */
38
/* # 'red' => "\033[31m", */
39
/* # 'green' => "\033[32m", */
40
/* # 'yellow' => "\033[33m", */
41
/* # 'blue' => "\033[34m", */
42
/* # 'magenta' => "\033[35m", */
43
/* # 'cyan' => "\033[36m", */
44
/* # 'white' => "\033[37m", */
47
const char*_cd_log_level_to_string(const GLogLevelFlags loglevel)
51
case G_LOG_LEVEL_CRITICAL:
52
return "\033[1;31mCRITICAL: \033[0m ";
53
case G_LOG_LEVEL_ERROR:
54
return "\033[1;31mERROR : \033[0m ";
55
case G_LOG_LEVEL_WARNING:
56
return "\033[1;38mwarning : \033[0m ";
57
case G_LOG_LEVEL_MESSAGE:
58
return "\033[1;32mmessage : \033[0m ";
59
case G_LOG_LEVEL_INFO:
60
return "\033[1;33minfo : \033[0m ";
61
case G_LOG_LEVEL_DEBUG:
62
return "\033[1;35mdebug : \033[0m ";
67
void cd_log_location(const GLogLevelFlags loglevel,
76
if (loglevel > s_gLogLevel)
78
g_print(_cd_log_level_to_string(loglevel));
79
g_print("\033[0;37m(%s:%s:%d) \033[%cm \n ", file, func, line, s_iLogColor);
80
va_start(args, format);
81
g_logv(G_LOG_DOMAIN, loglevel, format, args);
85
static void cairo_dock_log_handler(const gchar *log_domain,
86
GLogLevelFlags log_level,
90
if (log_level > s_gLogLevel)
92
g_print("%s\n", message);
95
void cd_log_init(gboolean bBlackTerminal)
97
g_log_set_default_handler(cairo_dock_log_handler, NULL);
98
s_iLogColor = (bBlackTerminal ? '1' : '0');
101
void cd_log_set_level(GLogLevelFlags loglevel)
103
s_gLogLevel = loglevel;
107
void cd_log_set_level_from_name (const gchar *cVerbosity)
110
cd_log_set_level(G_LOG_LEVEL_WARNING);
111
else if (!strcmp(cVerbosity, "debug"))
112
cd_log_set_level(G_LOG_LEVEL_DEBUG);
113
else if (!strcmp(cVerbosity, "message"))
114
cd_log_set_level(G_LOG_LEVEL_MESSAGE);
115
else if (!strcmp(cVerbosity, "warning"))
116
cd_log_set_level(G_LOG_LEVEL_WARNING);
117
else if (!strcmp(cVerbosity, "critical"))
118
cd_log_set_level(G_LOG_LEVEL_CRITICAL);
119
else if (!strcmp(cVerbosity, "error"))
120
cd_log_set_level(G_LOG_LEVEL_ERROR);
122
cd_log_set_level(G_LOG_LEVEL_WARNING);
123
cd_warning("bad verbosity option: default to warning");