-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.py
33 lines (23 loc) · 1.05 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
import os
import logging
def create_logger(log_directory, filename, stream=False):
info_filehandler = logging.FileHandler(os.path.join(log_directory, '{}_info.log'.format(filename)))
debug_filehandler = logging.FileHandler(os.path.join(log_directory, '{}_debug.log'.format(filename)))
formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')
info_filehandler.setFormatter(formatter)
debug_filehandler.setFormatter(formatter)
info_filehandler.setLevel(logging.INFO)
debug_filehandler.setLevel(logging.DEBUG)
logger = logging.getLogger()
for hdlr in logger.handlers[:]:
logger.removeHandler(hdlr)
if stream:
streamhandler = logging.StreamHandler(sys.stdout)
streamhandler.setFormatter(formatter)
streamhandler.setLevel(logging.DEBUG)
logger.addHandler(streamhandler)
logger.addHandler(info_filehandler)
logger.addHandler(debug_filehandler)
logger.setLevel(logging.DEBUG)
logging.getLogger('PIL.PngImagePlugin').setLevel(logging.ERROR)
return logger