贝娄
belogging的Python项目详细描述
不要与日志冲突…
基于环境变量的简单日志配置。
功能:
- Set logging level using environment variable LOG_LEVEL (defaults to ‘INFO’)
- Set which loggers to enable using environment variable LOGGERS (defaults to ‘’, everything)
- Always output to stdout
- Optional JSON formatter
- Completely disable logging setting LOG_LEVEL=DISABLED
要求:
- Python 3.5 and beyond
安装:
pip install belogging
示例:
简单应用:
# my_script.pyimportbeloggingbelogging.load()# ^^ this call is optional, only useful for customization# For example, to enable JSON output: belogging.load(json=True)# belogging.getLogger is just a sugar to logging.getLogger, you can# use logging.getLogger as usual (and recommended).logger=belogging.getLogger('foobar')logger.debug('test 1')logger.info('test 2')
执行:
# selecting LOG_LEVEL $ LOG_LEVEL=DEBUG python my_script.py # level=DEBUG message=test 1 # level=INFO message=test 2 # selecting LOGGERS $ LOGGERS=foobar python my_script.py # Both messages # Both $ LOGGERS=foobar LOG_LEVEL=INFO my_script.py # only level=INFO message=test 2
应用程序应该在初始化时调用`belogging.load()`。 第一个`__init__.py`将是一个很好的候选者,但是在调用 `logging`模块可以。
Django:
在您的项目中`settings.py`:
importbelogging# Disable django logging setupLOGGING_CONFIG=Nonebelogging.load()
在代码中,像往常一样使用`logging.getLogger()`。
$ exportLOG_LEVEL=WARNING $ ./manage.py runserver # It will output only logging messages with severity > WARNING
日志记录遵循层次结构,因此您可以轻松地选择或跳过一些日志记录消息:
$ exportLOGGERS=my_app.critical_a,my_app.critical_c,my_lib $ ./my-app.py # "my_app.critical_b messages" will be skipped # all messages from my_lib will show up
更改日志:
0.1.3
- 修复复制筛选器:使用格式化日志消息检测复制 (感谢@rodjjo)
0.1.2
- 添加缺少的测试断言
- 添加用于处理OrderedDict Self的锁。\u缓存
0.1.1
- 解决方法以防止loggerreplicationfilter中的keyerror异常
0.1.0
- 添加json格式化程序
- 小改进
0.0.2
- 添加了loggerreplicationfilter和enable_replication_filter选项
- 添加了bellogging.getlogger(sugar to logging.getlogger)
0.0.1
- 初始版本