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)

转载于:https://www.cnblogs.com/hqd2008/p/7749371.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值