-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlogger.py
More file actions
41 lines (33 loc) · 1.21 KB
/
logger.py
File metadata and controls
41 lines (33 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import logging
import os
from configuration import Configuration
class Logger:
def __init__(self, name):
self._config = Configuration()
name_without_spaces = name.replace(' ', '')
self._log_formatter = logging.Formatter(
self._config['LOG']['FORMAT'],
self._config['DEFAULT']['TIMESTAMP_FORMAT']
)
file_handler = logging.FileHandler(
os.path.join(self._config['LOG']['PATH'],
name_without_spaces.lower() + ".log"),
mode='w'
)
file_handler.setFormatter(self._log_formatter)
self._log = logging.getLogger(name_without_spaces)
log_level = eval(self._config['LOG']['LEVEL'])
logging.getLogger().setLevel(log_level)
logging.getLogger("werkzeug").setLevel(logging.ERROR)
self._log.setLevel(log_level)
self._log.addHandler(file_handler)
def debug(self, message):
self._log.debug(message)
def info(self, message):
self._log.info(message)
def warning(self, message):
self._log.warning(message)
def error(self, message):
self._log.error(message)
def critical(self, message):
self._log.critical(message)