-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoggerMixin.py
47 lines (40 loc) · 1.45 KB
/
LoggerMixin.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
#!/usr/local/bin/python
import logging, logging.handlers
from os import system
import sys
class LoggerMixin():
def __init__(self):
rootlogger = logging.getLogger()
#set overall level to debug, default is warning for root logger
rootlogger.setLevel(logging.DEBUG)
filelog = logging.handlers.TimedRotatingFileHandler(
'../logs/fortressLog.log',
when='midnight',
interval=1,
)
filelog.setLevel(logging.DEBUG)
fileformatter = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s')
filelog.setFormatter(fileformatter)
rootlogger.addHandler(filelog)
#setup logging to console
console = logging.StreamHandler()
console.setLevel(logging.INFO)
consoleformatter = logging.Formatter(
'%(asctime)-8s %(message)s',
datefmt='%m-%d %H:%M:%S',
)
console.setFormatter(consoleformatter)
rootlogger.addHandler(console)
def _debug(self, *args):
self._log(logging.DEBUG, *args)
def _info(self, *args):
print('\x1b[2K\r', end='') # clear existing line
sys.stdout.flush()
self._log(logging.INFO, *args)
def _log(self, level, *args):
logger = logging.getLogger(__name__)
message = ' '.join(map(str, args))
if (level == logging.DEBUG):
logger.debug(message)
elif (level == logging.INFO):
logger.info(message)