贝娄

belogging的Python项目详细描述


不要与日志冲突…

TravisCI Build StatusCoverage StatusPyPI VersionPyPI LicensePyPI latest


基于环境变量的简单日志配置。

功能:

  • 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

  • 初始版本

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Spring框架服务单元测试   在Java中遍历hashmaps的hashmap以检索字符串值   如何使用CodeQL检查Java注释是否具有特定属性?   java为什么在Spring Boot中访问此资源而不是登录弹出窗口需要始终获得完全身份验证   处理将多集计数转换为列表的过程   java另一个线性布局,没有出现按钮   eclipse Java映像加载未显示在jar中   java Junit类无法加载基本测试类ApplicationContext   java如何在main中使用my getvalues()方法打印列表   java Sonar,S128:切换案例应该以无条件的“中断”语句结束,而不是继续   java从socket读取字符串错误连接重置错误   java使用新数据刷新任意图表饼图   java通过异步运行lambda访问方法参数   java错误的结果一旦我处理try and catch