金字塔日志记录

发布于 2024-11-13 09:11:53 字数 787 浏览 4 评论 0原文

我有一个金字塔应用程序,我希望日志到达 stderr 和 stdout。标准输出应为“INFO”级别及以下。 stderr 应该是“WARN”或更高。我将如何更改我的 .ini 文件来执行此操作?

目前我正在这样记录,这被认为是正确的方法吗?

log = logger.getLogger(__name__)
log.info("update ...")
log.error("MAYDAY MAYDAY... BOOM!!!")

目前我正在使用默认日志记录,就是这样。

[loggers]
keys = root, app

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console

[logger_app]
level = WARN
handlers =
qualname = app

[handler_console]
class = StreamHandler
args = (sys.stderr,)                                                                                                                          
85 level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s

I have a pyramid application and I want the logs to got to stderr and stdout. stdout should be "INFO" level and below. stderr should be "WARN" and higher. How would I change my .ini file to do this?

Currently I am logging like this, is this considered the correct way?

log = logger.getLogger(__name__)
log.info("update ...")
log.error("MAYDAY MAYDAY... BOOM!!!")

Currently I am using the default logging, which is this.

[loggers]
keys = root, app

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console

[logger_app]
level = WARN
handlers =
qualname = app

[handler_console]
class = StreamHandler
args = (sys.stderr,)                                                                                                                          
85 level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇妻 2024-11-20 09:11:53

您可以将多个处理程序添加到根,以逗号分隔。如果您想在正常的“仅接受高于此日志记录级别的消息”标准(即仅调试消息)之外进行过滤,那么您需要使用日志过滤器之类的东西来根据特定级别接受/拒绝记录:
http://docs.python.org/library/logging.html#filter- object

您当前使用 log =logging.getLogger(__name__) 进行日志记录的方法是完全有效的,并且是组织日志记录层次结构的便捷方法。

You can add multiple handlers to the root, comma-delimited. If you want to filter outside of the normal "only accept messages above this logging level" criterion (i.e. only debug messages) then you need to use something like a logging filter to accept/reject records based on their specific levels:
http://docs.python.org/library/logging.html#filter-objects

Your current method of logging using log = logging.getLogger(__name__) is perfectly valid and a convenient way to organize the logging hierarchy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文