-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogfile.py
More file actions
32 lines (27 loc) · 1.24 KB
/
Copy pathlogfile.py
File metadata and controls
32 lines (27 loc) · 1.24 KB
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
import logging
def init(logFilename):
''' Output log to file and console '''
# Define a Handler and set a format which output to file
logging.basicConfig(
level=logging.DEBUG, # 定义输出到文件的log级别,
format='%(asctime)s %(filename)s : %(levelname)s %(message)s', # 定义输出log的格式
#datefmt='%Y-%m-%d,%H:%M:%S.%f', # 时间
filename=logFilename, # log文件名
filemode='w') # 写入模式“w”或“a”
# Define a Handler and set a format which output to console
console = logging.StreamHandler() # 定义console handler
console.setLevel(logging.INFO) # 定义该handler级别
formatter = logging.Formatter('%(asctime)s %(filename)s : %(levelname)s %(message)s') # 定义该handler格式
console.setFormatter(formatter)
# Create an instance
logging.getLogger().addHandler(console) # 实例化添加handler
# Print information # 输出日志级别
'''
logging.debug('logger debug message')
logging.info('logger info message')
logging.warning('logger warning message')
logging.error('logger error message')
logging.critical('logger critical message')
'''
def debug(message):
logging.debug(message)