1
2
3
4 """
5 Defines a logger based on Python's logger module.
6 """
7
8
9 import logging
10 import logging.handlers
11
12 import configuration
13
14
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
26 """
27 Create a logger object with a default verbosity corresponding to a
28 given loglevel.
29 """
30
31 __config = configuration.getConfig()
32 __loglevel_str = __config.get("Development","Verbosity_Level")
33 loglevel = MB_LOGLEVEL_MAPPING[__loglevel_str]
34
35
36 logger = logging.getLogger(MB_LOGGER_NAME)
37
38 logger.setLevel(loglevel)
39
40
41 handler.setLevel(loglevel)
42
43 formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
44
45 handler.setFormatter(formatter)
46
47
48 logger.addHandler(handler)
49 return logger
50