-
Notifications
You must be signed in to change notification settings - Fork 0
/
mylogging.py
37 lines (27 loc) · 1.03 KB
/
mylogging.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
# -*- coding:utf-8 -*-
import os
import logging
import logging.handlers
class MyLogger(logging.Logger):
def __init__(self, filename='log/test.log'):
logging.Logger.__init__(self, filename)
fmtHandler = logging.Formatter('%(asctime)s [%(filename)s %(funcName)s():%(lineno)s][%(levelname)s] %(message)s')
try:
consoleHd = logging.StreamHandler()
consoleHd.setLevel(logging.INFO)
consoleHd.setFormatter(fmtHandler)
self.addHandler(consoleHd)
except Exception as reason:
self.error("%s" % reason)
try:
os.makedirs(os.path.dirname(filename))
except Exception as e:
pass
try:
rtfileHd = logging.handlers.RotatingFileHandler(filename, maxBytes=10 * 1-24 * 1024, backupCount=5)
rtfileHd.setLevel(logging.INFO)
rtfileHd.setFormatter(fmtHandler)
self.addHandler(rtfileHd)
except Exception as reason:
self.error("%s" % reason)
return