import logging
'''
json格式
'''
def log_record(log_module_name, log_fname, log_level):
'''
日志记录模块
'''
op = {
'debug':logging.DEBUG,
'info':logging.INFO
'WARNING':logging.WARNING
'ERROR':logging.ERROR
'CRITICAL':logging.CRITICAL
}
log_level = op.get(log_level)
f = logging.FileHandler(log_fname, "a", "UTF-8")
fmt = logging.Formatter(
fmt='{"access_time":"%(asctime)s","access_name":"%(name)s","log_level":"%(levelname)s","log_module":"%(module)s","log_message":"%(message)s"}')
f.setFormatter(fmt)
loggerx = logging.Logger(log_module_name, level=log_level)
loggerx.addHandler(f)
return loggerx
# logger1 = log_record('test', 'test.log', 'debug')
# logger1.warning("test debug msg")
[py]logutils 给人用的日志记录模块-支持json格式
最新推荐文章于 2024-03-25 14:48:03 发布