forked from linfengYang/AugLPN_NILM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.py
29 lines (21 loc) · 778 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
26
27
28
import logging
import time
log_file_name = '{}.log'.format(time.strftime("%Y-%m-%d-%H:%M:%S").replace(':','-'))
with open(log_file_name, 'w'):
pass
logFormatter = logging.Formatter("%(asctime)s [%(levelname)-5.5s] %(message)s")
rootLogger = logging.getLogger()
rootLogger.setLevel(logging.DEBUG)
fileHandler = logging.FileHandler("{0}".format(log_file_name))
fileHandler.setFormatter(logFormatter)
rootLogger.addHandler(fileHandler)
consoleHandler = logging.StreamHandler()
consoleHandler.setFormatter(logFormatter)
rootLogger.addHandler(consoleHandler)
def log(string, level='info'):
if level == 'info':
rootLogger.info(string)
elif level == 'debug':
rootLogger.debug(string)
elif level == 'warning':
rootLogger.warning(string)