python loger 模板
2022/1/3 20:12:10
本文主要是介绍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)
这篇关于python loger 模板的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程
- 2024-11-17在FastAPI项目中添加一个生产级别的数据库——本地环境搭建指南
- 2024-11-16`PyMuPDF4LLM`:提取PDF数据的神器
- 2024-11-16四种数据科学Web界面框架快速对比:Rio、Reflex、Streamlit和Plotly Dash
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门