Mercurial > noffle
comparison src/log.c @ 462:de7f674d1224 noffle
[svn] * src/log.c: Rename log structure to logSettings to remove warning about
hiding built-in from GCC 3.3.1.
author | bears |
---|---|
date | Wed, 23 Jul 2003 10:26:49 +0100 |
parents | 5eece4dfd945 |
children |
comparison
equal
deleted
inserted
replaced
461:b540ecb6f218 | 462:de7f674d1224 |
---|---|
1 /* | 1 /* |
2 log.c | 2 log.c |
3 | 3 |
4 $Id: log.c 413 2002-12-27 21:48:25Z bears $ | 4 $Id: log.c 607 2003-07-23 09:26:49Z bears $ |
5 */ | 5 */ |
6 | 6 |
7 #if HAVE_CONFIG_H | 7 #if HAVE_CONFIG_H |
8 #include <config.h> | 8 #include <config.h> |
9 #endif | 9 #endif |
21 | 21 |
22 static struct | 22 static struct |
23 { | 23 { |
24 Bool interactive; | 24 Bool interactive; |
25 unsigned debugMask; | 25 unsigned debugMask; |
26 } log = { FALSE, DEFAULT_DBG_MASK }; | 26 } logSetting = { FALSE, DEFAULT_DBG_MASK }; |
27 | 27 |
28 void | 28 void |
29 Log_init( const char *name, Bool interactive, int facility ) | 29 Log_init( const char *name, Bool interactive, int facility ) |
30 { | 30 { |
31 int option = LOG_PID | LOG_CONS; | 31 int option = LOG_PID | LOG_CONS; |
32 | 32 |
33 log.interactive = interactive; | 33 logSetting.interactive = interactive; |
34 openlog( name, option, facility ); | 34 openlog( name, option, facility ); |
35 } | 35 } |
36 | 36 |
37 #define DO_LOG( LEVEL ) \ | 37 #define DO_LOG( LEVEL ) \ |
38 va_list ap; \ | 38 va_list ap; \ |
41 va_start( ap, fmt ); \ | 41 va_start( ap, fmt ); \ |
42 vsnprintf( t, MAXCHAR, fmt, ap ); \ | 42 vsnprintf( t, MAXCHAR, fmt, ap ); \ |
43 if ( MAXLENGTH < MAXCHAR ) \ | 43 if ( MAXLENGTH < MAXCHAR ) \ |
44 t[ MAXLENGTH ] = '\0'; \ | 44 t[ MAXLENGTH ] = '\0'; \ |
45 syslog( LEVEL, "%s", t ); \ | 45 syslog( LEVEL, "%s", t ); \ |
46 if ( log.interactive ) \ | 46 if ( logSetting.interactive ) \ |
47 fprintf( stderr, "%s\n", t ); \ | 47 fprintf( stderr, "%s\n", t ); \ |
48 va_end( ap ); | 48 va_end( ap ); |
49 | 49 |
50 void | 50 void |
51 Log_inf( const char *fmt, ... ) | 51 Log_inf( const char *fmt, ... ) |
77 } | 77 } |
78 | 78 |
79 void | 79 void |
80 Log_dbg( unsigned subsystem, const char *fmt, ... ) | 80 Log_dbg( unsigned subsystem, const char *fmt, ... ) |
81 { | 81 { |
82 if ( ( subsystem & log.debugMask ) != 0 ) { | 82 if ( ( subsystem & logSetting.debugMask ) != 0 ) { |
83 DO_LOG( LOG_DEBUG ); | 83 DO_LOG( LOG_DEBUG ); |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 void | 87 void |
89 { | 89 { |
90 /* A non-zero mask always include Noffle logs */ | 90 /* A non-zero mask always include Noffle logs */ |
91 if ( mask != 0 ) | 91 if ( mask != 0 ) |
92 mask |= LOG_DBG_NOFFLE; | 92 mask |= LOG_DBG_NOFFLE; |
93 | 93 |
94 log.debugMask = mask; | 94 logSetting.debugMask = mask; |
95 } | 95 } |
96 | 96 |
97 /* | 97 /* |
98 * A fatal error. Log it, close down as much as possible and | 98 * A fatal error. Log it, close down as much as possible and |
99 * exit with EXIT_FAILURE. | 99 * exit with EXIT_FAILURE. |