-
Notifications
You must be signed in to change notification settings - Fork 5
/
log.py
36 lines (27 loc) · 1.22 KB
/
log.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
import os
from lithoxyl import Logger, SensibleSink, SensibleFormatter, StreamEmitter, SensibleFilter
from lithoxyl.emitters import FileEmitter
class FixedFileEmitter(FileEmitter):
def __init__(self, filepath, encoding=None, **kwargs):
self.encoding = encoding
super(FixedFileEmitter, self).__init__(filepath, encoding, **kwargs)
CUR_PATH = os.path.dirname(os.path.abspath(__file__))
LOG_FILE_PATH = os.path.join(CUR_PATH, 'logs', 'update_log.txt')
tlog = Logger('toplog')
file_fmt = SensibleFormatter('{status_char}{iso_end_local_noms_notz} - {duration_s}s - {action_name} - {event_message}')
file_emt = FixedFileEmitter(LOG_FILE_PATH)
file_filter = SensibleFilter(success='critical',
failure='info',
exception='debug')
file_sink = SensibleSink(formatter=file_fmt,
emitter=file_emt,
filters=[file_filter])
tlog.add_sink(file_sink)
def set_debug(enable=True):
if not enable:
raise NotImplementedError()
dbg_fmtr = file_fmt
dbg_emtr = StreamEmitter('stderr')
dbg_sink = SensibleSink(formatter=dbg_fmtr,
emitter=dbg_emtr)
tlog.add_sink(dbg_sink)