dictconfig中的根记录器

dictconfig中的根记录器

本文介绍了dictconfig中的根记录器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为Django项目设置一个Sentry记录器.我将定义一个sentry处理程序,并将该处理程序放入具有error级别的根记录器中.

I want to setup a Sentry logger for a Django project. I will define a sentry handler and will put that handler in the root logger with error level.

根据 logging 模块,有一个特殊的root键:

同时在其他中放置一个名称为''的记录器,用于包含根记录器的配置

At the same time in other places a logger with name '' is used to contain configuration for the root logger.

这具有相同的效果吗?最好是什么?

Does this have the same effect? What is preferable?

>>> import logging
>>> logging.getLogger('') is logging.root
True
>>>

推荐答案

无论哪种方法都可以,因为名为''的记录器是根记录器.指定顶级键root可以使您在配置很多记录器时更加清楚自己的操作-''记录器配置可能会丢失在其他一组记录器中,而root键是相邻的loggers键,因此(理论上)应该会更加突出.

Either way will work, because the logger named '' is the root logger. Specifying the top-level key root makes it clearer what you're doing if you're configuring a lot of loggers - the '' logger configuration could be lost inside a group of others, whereas the root key is adjacent to the loggers key and so (in theory) should stand out more.

重申一下,名为root的键是顶级键;它不在loggers下.

To reiterate, the key named root is a top-level key; it's not under loggers.

这篇关于dictconfig中的根记录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 00:52
查看更多