码迷,mamicode.com
首页 > 编程语言 > 详细

python基础之ATM-5

时间:2017-10-29 11:02:26      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:ogg   handler   info   att   日志文件   文件备份   def   pytho   mat   

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

标签:ogg   handler   info   att   日志文件   文件备份   def   pytho   mat   

原文地址:http://www.cnblogs.com/hqd2008/p/7749371.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!