• 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)
  • 相关阅读:
    dubbo服务的运行方式(2)
    朱砂掌健身养生功
    吴清忠养生网
    易筋经十二式
    dubbo入门(1)
    jquery ajax error函数和及其参数详细说明
    com.rabbitmq.client.ShutdownSignalException
    centos 安装rabbitMQ
    SpringMVC @RequestBody接收Json对象字符串
    跨域
  • 原文地址:https://www.cnblogs.com/hqd2008/p/7749371.html
Copyright © 2020-2023  润新知