-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
30 lines (18 loc) · 812 Bytes
/
utils.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 os
import logging
import datetime
def logger_init(output_dir, log_level):
logging.disabled = False
timestamp = datetime.datetime.now().strftime("%Y-%m-%d-%H_%M_%S")
log_file_path_name = os.path.join(output_dir, 'log_' + timestamp)
logFormatter = logging.Formatter("%(asctime)s | %(filename)20s:%(lineno)s | %(funcName)20s() | %(message)s")
rootLogger = logging.getLogger()
fileHandler = logging.FileHandler(log_file_path_name)
fileHandler.setFormatter(logFormatter)
rootLogger.addHandler(fileHandler)
consoleHandler = logging.StreamHandler()
consoleHandler.setFormatter(logFormatter)
rootLogger.addHandler(consoleHandler)
rootLogger.setLevel(log_level)
logging.getLogger('PIL').setLevel(logging.ERROR)
return fileHandler, consoleHandler