• 记录日志


    import logging.handlers
    class Sdplog:
        logger = None
        levels = {
            "DEBUG" : logging.DEBUG,
            "INFO" : logging.INFO,
            "WARNING" : logging.WARNING,
            "ERROR" : logging.ERROR,
            "CRITICAL" : logging.CRITICAL}
     
        log_level = config.LogLevel
     
        if not exists(join(CodeHome, 'logs')): mkdir(join(CodeHome, 'logs'))
        log_file = join(CodeHome, 'logs', 'sys.log')
        log_max_byte = 10 * 1024 * 1024;
        log_backup_count = 5
        log_datefmt = '%Y-%m-%d %H:%M:%S'
     
        @staticmethod
        def getLogger():
            if Sdplog.logger is not None:
                return Sdplog.logger
     
            Sdplog.logger = logging.Logger("loggingmodule.Sdplog")
            log_handler = logging.handlers.RotatingFileHandler(filename = Sdplog.log_file,
                                  maxBytes = Sdplog.log_max_byte,
                                  backupCount = Sdplog.log_backup_count)
            log_fmt = logging.Formatter('%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', datefmt=Sdplog.log_datefmt)
            log_handler.setFormatter(log_fmt)
            Sdplog.logger.addHandler(log_handler)
            Sdplog.logger.setLevel(Sdplog.levels.get(Sdplog.log_level))
            return Sdplog.logger
     
    #调用
    logger = Sdplog.getLogger()
  • 相关阅读:
    Python_day1
    12/04
    Linux基础笔记
    八:动态规划-未名湖边的烦恼
    七:动态规划-数字三角形
    六:大数运算-减法运算
    五:大数运算-加法运算
    四:大数运算-乘法运算
    三:排序-幸运数字
    二:排序-果园
  • 原文地址:https://www.cnblogs.com/chenjingyi/p/5794724.html
Copyright © 2020-2023  润新知