-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.py
48 lines (36 loc) · 1.44 KB
/
Logger.py
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
42
43
44
45
46
47
48
import logging
class CustomFormatter(logging.Formatter):
"""Logging Formatter to add colors and count warning / errors"""
grey = "\x1b[38;21m"
yellow = "\x1b[33;21m"
red = "\x1b[31;21m"
bold_red = "\x1b[31;1m"
reset = "\x1b[0m"
blue = '\u001b[34m'
format = "[%(levelname)s]: %(asctime)s - %(message)s "
FORMATS = {
logging.DEBUG: grey + format + reset,
logging.INFO: blue + format + reset,
logging.WARNING: yellow + format + reset,
logging.ERROR: red + format + reset,
logging.CRITICAL: bold_red + format + reset
}
def format(self, record):
log_fmt = self.FORMATS.get(record.levelno)
formatter = logging.Formatter(log_fmt)
return formatter.format(record)
class Logger:
def custom_logger(self):
log = logging.getLogger('BDD_SPOT')
if not log.handlers:
log.setLevel(logging.DEBUG)
file = logging.FileHandler(filename='BDD_SPOT.log', mode='a')
console = logging.StreamHandler()
file.setLevel(logging.WARNING)
console.setLevel(logging.DEBUG)
file.setFormatter(logging.Formatter('%(levelname)s: %(asctime)s: %(message)s: %(process)d: %(processName)s',
datefmt='%d/%m %H:%M:%S'))
console.setFormatter(CustomFormatter())
log.addHandler(file)
log.addHandler(console)
return log