1 # synarere -- a highly modular and stable IRC bot.
2 # Copyright (C) 2010 Michael Rodriguez.
3 # Rights to this code are documented in docs/LICENSE.
7 # Import required Python module.
10 # Import required Python function.
11 from logging
import handlers
13 # Import required core modules.
16 # Make these references to the real methods.
17 debug
, info
, warning
, error
, critical
= None, None, None, None, None
20 '''Get the logging level.'''
22 if var
.conf
.get('logger', 'level')[0] == 'info':
24 elif var
.conf
.get('logger', 'level')[0] == 'warning':
25 return logging
.WARNING
26 elif var
.conf
.get('logger', 'level')[0] == 'debug':
28 elif var
.conf
.get('logger', 'level')[0] == 'error':
30 elif var
.conf
.get('logger', 'level')[0] == 'critical':
31 return logging
.CRITICAL
36 '''Initialise the logging subsystem.'''
38 global debug
, info
, warning
, error
, critical
40 var
.log
= logging
.getLogger('synarere')
42 # Set up logging to stderr if we're in foreground mode.
44 stream
= logging
.StreamHandler()
48 handler
= handlers
.RotatingFileHandler(filename
=var
.conf
.get('logger', 'path')[0], maxBytes
=var
.conf
.get('logger', 'max_size')[0], backupCount
=var
.conf
.get('logger', 'max_logs')[0])
49 formatter
= logging
.Formatter(var
.conf
.get('logger', 'format')[0])
51 handler
.setFormatter(formatter
)
54 stream_format
= logging
.Formatter(var
.conf
.get('logger', 'stream_format')[0])
55 stream
.setFormatter(stream_format
)
56 var
.log
.addHandler(stream
)
58 var
.log
.addHandler(handler
)
59 var
.log
.setLevel(get_level())
61 debug
, info
, warning
= var
.log
.debug
, var
.log
.info
, var
.log
.warning
62 error
, critical
= var
.log
.error
, var
.log
.critical