forked from hellohaptik/multi-task-NLP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger_.py
40 lines (34 loc) · 1.15 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
33
34
35
36
37
38
39
40
'''
Custom log object to use across all files
'''
import logging
def make_logger(name, logFile, debugMode = False, silent = False):
# Create a custom log
log = logging.getLogger(name)
log.setLevel(logging.DEBUG)
log.propagate = False
# Create handlers
#setting level
if debugMode:
c_handler = logging.StreamHandler()
f_handler = logging.FileHandler(logFile)
c_handler.setLevel(logging.DEBUG)
f_handler.setLevel(logging.DEBUG)
elif silent:
f_handler = logging.FileHandler(logFile)
f_handler.setLevel(logging.INFO)
else:
c_handler = logging.StreamHandler()
f_handler = logging.FileHandler(logFile)
c_handler.setLevel(logging.INFO)
f_handler.setLevel(logging.INFO)
# Create formatters and add it to handlers
f_format = logging.Formatter('%(levelname)s - %(message)s')
f_handler.setFormatter(f_format)
# Add handlers to the log
log.addHandler(f_handler)
if not silent:
c_format = logging.Formatter('%(levelname)s - %(message)s')
c_handler.setFormatter(c_format)
log.addHandler(c_handler)
return log