Package mathbench :: Package basement :: Module logging_utils
[hide private]

Source Code for Module mathbench.basement.logging_utils

 1  #!/usr/bin/python 
 2  # -*- coding: utf-8 -*- 
 3   
 4  """ 
 5  Defines a logger based on Python's logger module. 
 6  """ 
 7   
 8  # Load Python's logging utilities 
 9  import logging 
10  import logging.handlers 
11   
12  import configuration 
13   
14  # mapping usefull to interpret the options 
15  MB_LOGLEVEL_MAPPING = { 
16           
17          "DEBUG"         : logging.DEBUG, 
18          "INFO"          : logging.INFO, 
19          "ERROR"         : logging.ERROR, 
20          "CRITICAL"      : logging.CRITICAL, 
21  } 
22   
23  MB_LOGGER_NAME="mathbench" 
24   
25 -def CreateLogger(handler):
26 """ 27 Create a logger object with a default verbosity corresponding to a 28 given loglevel. 29 """ 30 # Get the options concerning the verbosity level 31 __config = configuration.getConfig() 32 __loglevel_str = __config.get("Development","Verbosity_Level") 33 loglevel = MB_LOGLEVEL_MAPPING[__loglevel_str] 34 35 # Create the logger 36 logger = logging.getLogger(MB_LOGGER_NAME) 37 # set the log level according to the app's configuration 38 logger.setLevel(loglevel) 39 40 # set default level for the handler 41 handler.setLevel(loglevel) 42 # create formatter 43 formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") 44 # add the formatter to the handler 45 handler.setFormatter(formatter) 46 47 # add the handler to the logger 48 logger.addHandler(handler) 49 return logger
50