-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlogger.py
52 lines (37 loc) · 1.33 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
41
42
43
44
45
46
47
48
49
50
51
52
import logging
class Logger:
def __init__(
self,
opt,
logging_level=logging.INFO,
file_level=logging.INFO,
stream_level=logging.INFO
):
self.opt = opt
self.log_path = opt.log_path
self.logging_level = logging_level
self.file_level = file_level
self.stream_level = stream_level
self.logger = logging.getLogger('logger.log')
self.logger.setLevel(self.logging_level)
self.configure()
def configure(self):
log_format = logging.Formatter('%(levelname)s: %(message)s') #%(asctime)s
stream_handler = logging.StreamHandler()
stream_handler.setLevel(self.stream_level)
stream_handler.setFormatter(log_format)
file_handler = logging.FileHandler(self.log_path)
file_handler.setLevel(self.file_level)
file_handler.setFormatter(log_format)
self.logger.addHandler(file_handler)
self.logger.addHandler(stream_handler)
def debug(self, message):
self.logger.debug(message)
def info(self, message):
self.logger.info(message)
def warn(self, message):
self.logger.warning(message)
def error(self, message):
self.logger.error(message)
def critical(self, message):
self.logger.critical(message)