python项目的一个简单的可配置记录器
config-logger的Python项目详细描述
说明
config logger包是一个基本的可配置记录器它从 外部yaml、json文件或来自给定的python字典并对其进行验证。这本词典的内容是 在Configuration dictionary schema中描述。这个包目前在Python2.7上测试
用法
从外部.yaml或.json文件配置
#logging.yaml contains the configuration data which defines the logging in your project from config_logger import Logger logger = Logger(name='my_logger', cfg_path='/path/to/logging.yaml') logger.info("This will be written in a file called info.log")
控制台输出
2017-01-31 12:20:32,693 - my_logger - INFO - This will be written in a file called info.log
从字典配置
log_config = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'basic': { 'format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s' } }, 'handlers': { 'console': { 'class': 'logging.StreamHandler', 'formatter': 'basic', 'level': 'WARNING', 'stream': 'ext://sys.stdout' } 'root': { 'handlers': ['console'], 'level': 'WARNING' } } from config_logger import Logger logger = Logger(name='my_logger', default_conf=log_config) logger.warning("This will be written in a file called warning.log")
控制台输出
2017-01-31 13:12:56,002 - my_logger - WARNING - This will be written in a file called warning.log
注意:可以在this repo中找到配置记录器支持的日志配置文件示例。
许可证
这个项目是由麻省理工学院授权的。