-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.py
41 lines (37 loc) · 1.28 KB
/
log.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
# -*- coding: utf-8 -*-
# @File : 日志封装文件
'''日志模块'''
import os
import logbook
from logbook.more import ColorizedStderrHandler
from functools import wraps
check_path='.'
LOG_DIR = os.path.join(check_path, 'log')
file_stream = False
if not os.path.exists(LOG_DIR):
os.makedirs(LOG_DIR)
file_stream = True
# 获取日志
def get_logger(name='', file_log=file_stream, level=''):
""" get logger Factory function """
logbook.set_datetime_format('local')
ColorizedStderrHandler(bubble=False, level=level).push_thread()
logbook.TimedRotatingFileHandler(
os.path.join(LOG_DIR, '%s.log' % name),
date_format='%Y-%m-%d-%H', bubble=True, encoding='utf-8').push_thread()
return logbook.Logger(name)
LOG = get_logger(file_log=file_stream, level='INFO')
#log装饰器
def logger(param):
""" fcuntion from logger meta """
def wrap(function):
""" logger wrapper """
@wraps(function)
def _wrap(*args, **kwargs):
""" wrap tool """
LOG.info("当前模块 {}".format(param))
LOG.info("全部args参数参数信息 , {}".format(str(args)))
LOG.info("全部kwargs参数信息 , {}".format(str(kwargs)))
return function(*args, **kwargs)
return _wrap
return wrap