-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlogger.py
More file actions
39 lines (34 loc) · 979 Bytes
/
logger.py
File metadata and controls
39 lines (34 loc) · 979 Bytes
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
# -*- coding: utf-8 -*-
import logging
import logging.handlers
def create_logger(filename):
handle = logging.handlers.TimedRotatingFileHandler( filename = filename,
when='h',
interval=1,
backupCount=72 )
#handle.setLevel(logging.INFO)
fmt = logging.Formatter(fmt='%(asctime)s %(filename)s [line:%(lineno)d] [%(levelname)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S' )
handle.setFormatter(fmt)
logger = logging.getLogger()
logger.addHandler(handle)
logger.setLevel(logging.DEBUG)
#logger.setLevel(logging.INFO)
#logger.propagate = False
return logger
logger = None
class SLogger():
def __init__(self):
pass
@classmethod
def init_logger(cls, filename):
global logger
if not logger:
logger = create_logger(filename)
return logger
if __name__ == "__main__":
logger = SLogger.init_logger("../log/test_log.log")
logger.info('start to init IP pool ......')
#test mem leak
while True:
logger.info('xxxxxxxxxxxxxxxxx')