zoukankan      html  css  js  c++  java
  • 08-02-loggin-模块

    程序员看的格式

    standard_format = '[%(asctime)s][%(threadName)s:%(thread)d][task_id:%(name)s][%(filename)s:%(lineno)d]'
    '[%(levelname)s][%(message)s]' #其中name为getlogger指定的名字
    logfile_path1 = "coder.log"

    老板看的格式

    simple_format = '[%(levelname)s][%(asctime)s]%(message)s'
    logfile_path2 = "boss.log"

    LOGGING_DIC = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
    'standard': {
    'format': standard_format
    },
    'simple': {
    'format': simple_format
    },
    },
    'filters': {},
    'handlers': {
    #打印到终端的日志
    'console': {
    'level': 'DEBUG',
    'class': 'logging.StreamHandler', # 打印到屏幕
    'formatter': 'simple'
    },
    #打印到文件的日志,收集info及以上的日志
    'std': {
    'level': 'DEBUG',
    'class': 'logging.handlers.RotatingFileHandler', # 保存到文件
    'formatter': 'standard',
    'filename': logfile_path1, # 日志文件
    'maxBytes': 102410245, # 日志大小 5M
    'backupCount': 5, #日志文件最大个数
    'encoding': 'utf-8', # 日志文件的编码
    },
    'boss': {
    'level': 'DEBUG',
    'class': 'logging.handlers.RotatingFileHandler', # 保存到文件
    'formatter': 'simple',
    'filename': logfile_path2, # 日志文件
    'maxBytes': 1024 * 1024 * 5, # 日志大小 5M
    'backupCount': 5, # 日志文件最大个数
    'encoding': 'utf-8', # 日志文件的编码
    }
    },
    'loggers': {
    #logging.getLogger(name)拿到的logger配置
    'aa': {
    'handlers': ['std', 'console',"boss"], # 这里把上面定义的handler都加上,即log数据会同时输出到三个位置
    'level': 'INFO',
    'propagate': True, # 向上(更高level的logger)传递
    },
    },
    }

  • 相关阅读:
    asp.net六大对象
    python学习之类和实例的属性;装饰器@property
    第一次写博客,不知道写什么,就随便写一点咯
    Bash脚本编写初体验
    python学习之参数传递
    2016.9.30词法分析程序 108
    实验三 108
    10.28实验二 108
    词法分析实验报告 108
    组合数据类型练习,综合练习 108
  • 原文地址:https://www.cnblogs.com/qiangyuzhou/p/10899746.html
Copyright © 2011-2022 走看看