-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlogger.py
25 lines (23 loc) · 809 Bytes
/
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
import logging
import config
loggers = {}
def getLogger(analysisID=0,host='server'):
# log file
logfile = "{}/{}".format(config.dir.log_dir,"{}.log".format(host))
# create logger
if loggers.get(host):
return loggers.get(host)
else:
logger = logging.getLogger(host)
logger.setLevel(logging.DEBUG)
# create console handler and set level to debug
ch = logging.FileHandler(logfile, mode='a', encoding='utf-8')
ch.setLevel(logging.DEBUG)
# create formatter
formatter = logging.Formatter('%(asctime)s: [%(levelname)s]['+str(analysisID)+'] - %(message)s')
# add formatter to ch
ch.setFormatter(formatter)
# add ch to logger
logger.addHandler(ch)
loggers[host] = logger
return logger