forked from Madi-S/Lead-Generation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger_config.py
35 lines (25 loc) · 1020 Bytes
/
logger_config.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
import logging
def get_logger(name: str):
'''
Get full configured logger with pre-build handlers and formatters
:param name: Name of the logger
:return: returns full-fledged logger
'''
if isinstance(name, str):
f_formatter = logging.Formatter(
fmt='%(asctime)s - %(levelname)s | %(filename)s/%(funcName)s/%(lineno)d | %(message)s')
s_formatter = logging.Formatter(
fmt='%(levelname)s|%(name)s: %(message)s')
s_handler = logging.StreamHandler()
s_handler.setLevel(logging.DEBUG)
s_handler.setFormatter(s_formatter)
f_handler = logging.FileHandler('pylg.log', 'a')
f_handler.setLevel(logging.WARNING)
f_handler.setFormatter(f_formatter)
logger = logging.getLogger(name)
logger.setLevel(logging.DEBUG)
logger.propagate = False
logger.addHandler(s_handler)
logger.addHandler(f_handler)
return logger
raise TypeError('Logger name must be string')