author | Mikael Hallendal <micke@imendio.com> |
Sun, 29 Apr 2007 22:09:44 +0200 | |
changeset 265 | ebfc8419758d |
parent 99 | 81e9d035de02 |
child 213 | 27567fb5d37b |
permissions | -rw-r--r-- |
1 | 1 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
2 |
/* |
|
99
81e9d035de02
2004-10-05 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
84
diff
changeset
|
3 |
* Copyright (C) 2003 Imendio AB |
1 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU Lesser 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. |
|
9 |
* |
|
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 |
* Lesser General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU Lesser 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. |
|
19 |
*/ |
|
20 |
||
21 |
#include "lm-debug.h" |
|
22 |
||
23 |
#ifndef LM_NO_DEBUG |
|
24 |
||
25 |
static LmLogLevelFlags debug_flags = 0; |
|
26 |
static gboolean initialized = FALSE; |
|
27 |
||
28 |
static const GDebugKey debug_keys[] = { |
|
29 |
{"VERBOSE", LM_LOG_LEVEL_VERBOSE}, |
|
30 |
{"NET", LM_LOG_LEVEL_NET}, |
|
31 |
{"PARSER", LM_LOG_LEVEL_PARSER}, |
|
32 |
{"ALL", LM_LOG_LEVEL_ALL} |
|
33 |
}; |
|
34 |
||
35 |
#define NUM_DEBUG_KEYS (sizeof (debug_keys) / sizeof (GDebugKey)) |
|
36 |
||
37 |
static void |
|
38 |
debug_log_handler (const gchar *log_domain, |
|
39 |
GLogLevelFlags log_level, |
|
40 |
const gchar *message, |
|
41 |
gpointer user_data) |
|
42 |
{ |
|
43 |
if (debug_flags & log_level) { |
|
44 |
if (log_level & LM_LOG_LEVEL_VERBOSE) { |
|
45 |
g_print ("*** "); |
|
46 |
} |
|
47 |
else if (log_level & LM_LOG_LEVEL_PARSER) { |
|
48 |
g_print ("LM-PARSER: "); |
|
49 |
} |
|
50 |
||
51 |
g_print ("%s", message); |
|
52 |
} |
|
53 |
} |
|
54 |
||
19
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
55 |
/** |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
56 |
* lm_debug_init |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
57 |
* |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
58 |
* Initialized the debug system. |
bb3195f74ac7
2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
59 |
**/ |
1 | 60 |
void |
61 |
lm_debug_init (void) |
|
62 |
{ |
|
63 |
const gchar *env_lm_debug; |
|
64 |
||
65 |
if (initialized) { |
|
66 |
return; |
|
67 |
} |
|
68 |
||
69 |
env_lm_debug = g_getenv ("LM_DEBUG"); |
|
70 |
if (env_lm_debug) { |
|
71 |
debug_flags = g_parse_debug_string (env_lm_debug, debug_keys, |
|
72 |
NUM_DEBUG_KEYS); |
|
73 |
} |
|
74 |
||
75 |
g_log_set_handler (LM_LOG_DOMAIN, LM_LOG_LEVEL_ALL, |
|
76 |
debug_log_handler, NULL); |
|
77 |
||
78 |
initialized = TRUE; |
|
79 |
} |
|
80 |
#endif /* LM_NO_DEBUG */ |
|
81 |