We want to pop the first item off of the deque instead of the last so we don't end...
[synarere.git] / core / logger.py
blobd5a7ebc52d8b1e0321050304507b3ffad45f4c36
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.
5 '''Logger facility.'''
7 # Import required Python module.
8 import logging
10 # Import required Python function.
11 from logging import handlers
13 # Import required core modules.
14 import var
16 # Make these references to the real methods.
17 debug, info, warning, error, critical = None, None, None, None, None
19 def get_level():
20 '''Get the logging level.'''
22 if var.conf.get('logger', 'level')[0] == 'info':
23 return logging.INFO
24 elif var.conf.get('logger', 'level')[0] == 'warning':
25 return logging.WARNING
26 elif var.conf.get('logger', 'level')[0] == 'debug':
27 return logging.DEBUG
28 elif var.conf.get('logger', 'level')[0] == 'error':
29 return logging.ERROR
30 elif var.conf.get('logger', 'level')[0] == 'critical':
31 return logging.CRITICAL
33 return logging.INFO
35 def init():
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.
43 if not var.fork:
44 stream = logging.StreamHandler()
45 else:
46 stream = None
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)
53 if stream:
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