• python loger 模板


    一、python loger 模板

    def init_logger(app_flask):
        log_conf_dir = {
            "version": 1,
            "disable_existing_loggers": False,
            "formatters": {
                "standard": {
                    # 其中name为getlogger指定的名字
                    "format": "[%(asctime)s][%(threadName)s:%(thread)d][%(name)s][%(filename)s:%(lineno)d][%(levelname)s] %(message)s"
                }
            },
            "filters": {},
            "handlers": {
                # 打印到终端的日志
                "console": {
                    "level": "DEBUG",
                    # 打印到屏幕
                    "class": "logging.StreamHandler",
                    "formatter": "standard",
                },
                # 打印到文件的日志,收集info及以上的日志
                "default": {
                    "level": "INFO",
                    # 保存到文件
                    "class": "logging.handlers.RotatingFileHandler",
                    "formatter": "standard",
                    "filename": LOG_FILE_NAME,
                    # 日志大小 5M
                    "maxBytes": 1024 * 1024 * 5,
                    "backupCount": 5,
                    "encoding": "utf-8",
                },
                # 打印到文件的日志:收集错误及以上的日志
                "error": {
                    "level": "ERROR",
                    "class": "logging.handlers.RotatingFileHandler",
                    "filename": LOG_ERROR_FILE_NAME,
                    "maxBytes": 1024 * 1024 * 5,
                    "backupCount": 5,
                    "formatter": "standard",
                    "encoding": "utf-8",
                },
            },
            "loggers": {
                # logging.getLogger(__name__)拿到的logger配置
                app_name: {
                    "handlers": [
                        "default",
                        "console",
                        "error",
                    ],
                    "level": LOG_LEVEL,
                    # True 向上(更高level的logger)传递
                    "propagate": False,
                },
                # werkzeug 底层的日志
                "werkzeug": {
                    "handlers": [
                        "default",
                        "console",
                        "error",
                    ],
                    "level": "ERROR",
                    "propagate": False,
                },
            },
        }
        dictConfig(log_conf_dir)
    
    ``def init_logger(app_flask): log_conf_dir = { "version": 1, "disable_existing_loggers": False, "formatters": { "standard": { # 其中name为getlogger指定的名字 "format": "[%(asctime)s][%(threadName)s:%(thread)d][%(name)s][%(filename)s:%(lineno)d][%(levelname)s] %(message)s" } }, "filters": {}, "handlers": { # 打印到终端的日志 "console": { "level": "DEBUG", # 打印到屏幕 "class": "logging.StreamHandler", "formatter": "standard", }, # 打印到文件的日志,收集info及以上的日志 "default": { "level": "INFO", # 保存到文件 "class": "logging.handlers.RotatingFileHandler", "formatter": "standard", "filename": LOG_FILE_NAME, # 日志大小 5M "maxBytes": 1024 * 1024 * 5, "backupCount": 5, "encoding": "utf-8", }, # 打印到文件的日志:收集错误及以上的日志 "error": { "level": "ERROR", "class": "logging.handlers.RotatingFileHandler", "filename": LOG_ERROR_FILE_NAME, "maxBytes": 1024 * 1024 * 5, "backupCount": 5, "formatter": "standard", "encoding": "utf-8", }, }, "loggers": { # logging.getLogger(__name__)拿到的logger配置 app_name: { "handlers": [ "default", "console", "error", ], "level": LOG_LEVEL, # True 向上(更高level的logger)传递 "propagate": False, }, # werkzeug 底层的日志 "werkzeug": { "handlers": [ "default", "console", "error", ], "level": "ERROR", "propagate": False, }, }, } dictConfig(log_conf_dir)
  • 相关阅读:
    自定义tabbar
    数据存储: sqlite,coredata plist 归档
    分享(微信,微博,人人)
    OAuth协议与第三方登录:(QQ,百度,微信,微博)
    修改后台来测试APP的方法
    mysql 数据库优化之路
    tcp协议在定位中的应用(2)
    tcp协议在定位中的应用
    计算机术语中一些歧义
    网络常见问题背后的原因
  • 原文地址:https://www.cnblogs.com/Klay/p/15760239.html
Copyright © 2020-2023  润新知