-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.py
36 lines (28 loc) · 958 Bytes
/
test.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
import time
import logging
from safe_logger import TimedRotatingFileHandlerSafe
class NullHandler(logging.Handler):
def emit(self, record):
pass
def write(self, *args, **kwargs):
pass
LOG_FILE = 'logs/debug.log'
ERR_FILE = 'logs/error.log'
FORMAT = '[%(asctime)s] [%(levelname)s] [PID: '+str(os.getpid())+'] [%(name)s]: %(message)s'
FORMATTER = logging.Formatter(FORMAT)
logging.basicConfig(level=logging.DEBUG, stream=NullHandler())
root = logging.root
log_handler = TimedRotatingFileHandlerSafe(LOG_FILE, when='MIDNIGHT')
log_handler.setLevel(logging.DEBUG)
log_handler.setFormatter(FORMATTER)
root.addHandler(log_handler)
err_handler = TimedRotatingFileHandlerSafe(ERR_FILE, when='MIDNIGHT')
err_handler.setLevel(logging.ERROR)
err_handler.setFormatter(FORMATTER)
root.addHandler(err_handler)
lg = logging.getLogger('testme')
while True:
lg.debug('test debug')
lg.error('test error')
time.sleep(0.5)