通过对象图了解Python日志记录 [英] Understanding Python logging through an object diagram

查看:101
本文介绍了通过对象图了解Python日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该图显示了用于设置Python日志记录对象的对象图.设置记录器对象后,正在进行的程序将仅与(三个)记录器对象进行交互.

The diagram shows the object diagram for setting up Python logging objects. Once the logger objects are set, the ongoing program will interact with just the (three) logger objects.

在此对象图中,适当的对象以白色背景显示.标量显示为黄色背景.箭头是指针或设置.因此,从左文件处理程序到左上文件处理程序日志级别的箭头表示后者是前者的参数.

In this object diagram, proper objects are shown with a white background. Scalars are shown with a yellow background. The arrows are a pointer, or a setting. Hence the arrow from the left file handler to the top left file handler log level signal that the latter is a parameter to the former.

A:记录器2和记录器3共享同一个文件处理程序,因此它们的输出将混合(按时间戳记).

A: Loggers 2 and 3 share the same file handler, hence their output will mix (by timestamp).

B:记录器1使用其他文件处理程序,因此它将具有自己的输出文件.

B: Logger 1 uses a different file handler, hence it will have its own output file.

C:此对象图可能涉及五个不同的日志级别.

C: There are potentially five different log levels involved for this object diagram.

这三个陈述正确吗?

推荐答案

所有三个语句都是正确的,但是第三个语句有点奇怪.

All three statements are correct, the third is a little weird though.

A:记录器2和记录器3共享同一个文件处理程序,因此它们的输出将混合(按时间戳记).

A: Loggers 2 and 3 share the same file handler, hence their output will mix (by timestamp).

请注意,记录器2和3可以具有其他处理程序,它们可以共享更多的处理程序,也可以拥有自己的处理程序.每个记录器可以有多个处理程序.

Note that loggers 2 and 3 could have additional handlers, they could share more or have their own. Each logger can have multiple handlers.

B:记录器1使用其他文件处理程序,因此它将具有自己的输出文件.

B: Logger 1 uses a different file handler, hence it will have its own output file.

一个记录器,一个处理程序,一个输出文件.容易理解.

One logger, one handler, one output file. Easy to understand.

C:此对象图可能涉及五个不同的日志级别.

C: There are potentially five different log levels involved for this object diagram.

是的,但是与每个记录器关联的三个级别所做的事情与与处理程序关联的级别有所不同.每个记录器上的级别告诉记录器完全忽略该级别以下的所有消息.因此,例如,如果您有一个处理DEBUG消息的处理程序,但该处理程序位于设置了INFO级别的记录器上,则该处理程序将永远不会从该特定记录器发送DEBUG消息.因此,记录器将获取记录器级别或更高级别的所有消息,并将其转发给它拥有的每个处理程序.在Python日志记录高级教程中查看以下流程图:

True, but the three levels associated with each logger do something different than the levels associated with the handlers. The levels on each logger tell the logger to entirely ignore all messages below that level. So for instance, if you have a handler that handles DEBUG messages, but that is on a logger with INFO set as the level, the handler will never send DEBUG messages from that specific logger. So, the logger will take all messages at or above the logger level, and forward them off to each handler it has. Check the following flow diagram from the Python logging advanced tutorial:

该图很容易说明,因此我不会对其进行过多地说明.但这有望消除您的所有疑问.

The diagram is pretty self explanatory, so I won't rehash it too much. But this should hopefully clear all your doubts.

这篇关于通过对象图了解Python日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆