/usr/share/voctomix/voctocore/lib/loghandler.py is in voctomix-core 1.0+git4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 53 54 55 56 57 | import logging
import time
class LogFormatter(logging.Formatter):
def __init__(self, docolor, timestamps=False):
super().__init__()
self.docolor = docolor
self.timestamps = timestamps
def formatMessage(self, record):
if self.docolor:
c_lvl = 33
c_mod = 32
c_msg = 0
if record.levelno == logging.WARNING:
c_lvl = 31
# c_mod = 33
c_msg = 33
elif record.levelno > logging.WARNING:
c_lvl = 31
c_mod = 31
c_msg = 31
fmt = ''.join([
'\x1b[%dm' % c_lvl, # set levelname color
'%(levelname)8s', # print levelname
'\x1b[0m', # reset formatting
'\x1b[%dm' % c_mod, # set name color
' %(name)s', # print name
'\x1b[%dm' % c_msg, # set message color
': %(message)s', # print message
'\x1b[0m' # reset formatting
])
else:
fmt = '%(levelname)8s %(name)s: %(message)s'
if self.timestamps:
fmt = '%(asctime)s ' + fmt
if 'asctime' not in record.__dict__:
record.__dict__['asctime'] = time.strftime(
"%Y-%m-%d %H:%M:%S",
time.localtime(record.__dict__['created'])
)
return fmt % record.__dict__
class LogHandler(logging.StreamHandler):
def __init__(self, docolor, timestamps):
super().__init__()
self.setFormatter(LogFormatter(docolor, timestamps))
|