-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlog_class.py
58 lines (45 loc) · 1.24 KB
/
log_class.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
48
49
50
51
52
53
54
55
56
57
# -*- coding:utf-8 -*-
import logging,os
'''
Log Level
logging.DEBUG
logging.INFO
logging.WARNING
logging.ERROR
logging.CRITICAL
logyyx = Logger('yyx.log',logging.ERROR,logging.DEBUG)
logyyx.debug('debug message')
logyyx.info('info message')
logyyx.war('warning message')
logyyx.error('error message')
logyyx.cri('critical message')
'''
class Logger:
def __init__(self, path, clevel, Flevel):
#Create logger
self.logger = logging.getLogger(path)
self.logger.setLevel(Flevel)
#Set handler output format
formatter = logging.Formatter('[%(asctime)s] - [%(levelname)s] - %(message)s', '%Y-%m-%d %H:%M:%S')
#Set handler output to console
ch = logging.StreamHandler()
ch.setFormatter(formatter)
ch.setLevel(clevel)
#Set the file log
fh = logging.FileHandler(path)
fh.setFormatter(formatter)
fh.setLevel(Flevel)
#Add logger handler
self.logger.addHandler(ch)
self.logger.addHandler(fh)
def debug(self,message):
self.logger.debug(message)
def info(self,message):
self.logger.info(message)
def warn(self,message):
self.logger.warn(message)
def error(self,message):
self.logger.error(message)
#Critical
def cri(self,message):
self.logger.critical(message)