为任何想要配置日志参数的人提供一个函数,只要在应用程序启动时调用iNITHLogLogyFig,就可以使用在Python 3中构建的日志模块,而不需要其他配置。该模块支持控制台处理程序、RoATTIN FILE处理程序和SMTPHandler,并且可以根据您的要求更改配置参数。
log-config的Python项目详细描述
为任何想轻松配置日志参数的人提供一个函数,只要在你的应用程序启动时调用init_log_config,你就可以使用python3中构建的日志模块,而不需要任何其他配置器。该模块支持consolehandler、rotatingfilehandler和smtphandler,您可以根据需要更改配置参数。
元
- 作者:吴查尔斯
- 电子邮件:wcadaydayup@163.com
- 维修人员:吴查尔斯
- 电子邮件:wcadaydayup@163.com
- 状态:积极发展、稳定、保持
[![版本](https://img.shields.io/pypi/v/log_config.svg)](https://pypi.python.org/pypi/log_config) [![github](https://github.com/wcadaydayup/log_config.svg?branch=master)](https://github.com/wcadaydayup/log_config)
安装
只需在virtualenv中运行以下命令:
$ pip install log_config or $ pip install git+https://github.com/wcadaydayup/log_config
用法
在任何需要使用python3内置日志的地方导入日志配置函数:
from log_config.log_config import init_log_config
启动应用程序时调用init_log_config(),当然可以通过从log_config.log_config导入其他变量来修改日志文件路径、日志级别等:
init_log_config()
日志配置就绪,您可以使用日志模块而无需任何其他配置:
import logging logger = logging.getLogger() logger.debug("this is a message of debug level.")
然后,您将在控制台和日志文件中看到当前目录中的输出消息:
configure_installed_apps_logger(logging.INFO, verbose=True, filename='django-project.log')
如果call init_log_config(use_mail=true),您还可以接收电子邮件通知,当然您应该提供正确的电子邮件参数:
import log_config.log_config as lf lf.EMAIL_HOST = "xxx.smtp.com" lf.FROM = "youraccount@xx.com" lf.TO = "a@xx.com;b@xx.com" ... init_log_config(use_mail=True)