-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsig_logger.py
45 lines (36 loc) · 1.34 KB
/
sig_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
import os
import logging
from logging.handlers import TimedRotatingFileHandler
class SigLogger():
def __init__(self, name, uilogger=None):
if not os.path.isdir('logs'):
os.makedirs('logs')
self.logger = logging.getLogger(name)
self.logger.setLevel(logging.INFO)
# create file, formatter and add it to the handlers
fh = TimedRotatingFileHandler('logs/' + name + '.log', when='d',
interval=1, backupCount=10)
fh.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(process)d - %(name)s '
'(%(lineno)d) %(levelname)s: %(message)s',
"%Y-%m-%d %H:%M:%S")
fh.setFormatter(formatter)
self.logger.addHandler(fh)
self.uilogger = uilogger
def log_all(self, message, level='info'):
if not message:
return
if level == 'info':
self.logger.info(message)
if self.uilogger:
self.uilogger.info(message)
else:
self.logger.error(message)
if self.uilogger:
self.uilogger.error(message)
def info(self, msg):
if msg:
self.logger.info(msg)
def error(self, msg):
if msg:
self.logger.error(msg)