-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlog.py
More file actions
31 lines (23 loc) · 803 Bytes
/
log.py
File metadata and controls
31 lines (23 loc) · 803 Bytes
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
"""Log module
Author: YANG, Austin Liu
"""
import logging
class MyLogger:
logger = logging.getLogger('mylogger')
logger.setLevel(logging.DEBUG)
formatter_ch = logging.Formatter('%(message)s')
formatter_fh = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
def __init__(self):
# Screen log
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
ch.setFormatter(self.formatter_ch)
self.logger.addHandler(ch)
def addFileHandler(self, directory_log):
# File log
filename = 'log/' + directory_log + '/log' + directory_log + '.log'
fh = logging.FileHandler(filename)
fh.setLevel(logging.INFO)
fh.setFormatter(self.formatter_fh)
self.logger.addHandler(fh)