python基础之ATM-5
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python基础之ATM-5相关的知识,希望对你有一定的参考价值。
import logging
import os
import sys
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)
from conf import settings
from logging import handlers
‘‘‘
本模块是logging模块,实现的日志的记录
‘‘‘
def write_logger(log_params,info):
logger = logging.getLogger(‘ATM_LOG‘)
logger.setLevel(logging.DEBUG)
log_path = log_handler(log_params)
log_file = ‘%s.log‘ % (log_path)
# fh = logging.FileHandler(log_file) #普通
# fh = handlers.RotatingFileHandler(filename=log_file,maxBytes=10,backupCount=3) #按大小备份
fh = handlers.TimedRotatingFileHandler(filename=log_file, when="midnight", interval=5, backupCount=3) #每日凌晨生成一个日志文件,原文件备份
fh.setLevel(logging.DEBUG)
fh_formatter = logging.Formatter(‘%(asctime)s %(levelname)s:%(message)s‘)
fh.setFormatter(fh_formatter)
logger.addHandler(fh)
logger.debug(info)
logger.removeHandler(fh)
def file_log_handler(log_params):
log_path = ‘%s\%s‘%(log_params["path"],log_params["name"])
return log_path
def log_handler(log_params):
if log_params["file"] == "data":
return file_log_handler(log_params)
elif log_params["file"] == "trans":
return file_log_handler(log_params)
以上是关于python基础之ATM-5的主要内容,如果未能解决你的问题,请参考以下文章