将库的NullHandler集成到我自己的项目记录器中 [英] Integrate NullHandler of library into my own projects logger

查看:61
本文介绍了将库的NullHandler集成到我自己的项目记录器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发自己的库以及使用该库的应用.

I'm developing a library of my own and an app that uses that library.

我想同时使用记录项目.

阅读我知道我在库中的根记录器应包含一个NullHandler.但是我对如何使用项目应该如何到达在该库中创建的LogRecrods的部分了解(这样,这些记录将与项目记录一起处理).

After reading this I know that my root logger in the library should contain a NullHandler. But the part on how my using project should reach to the LogRecrods created in that library (so those will be handled alongside the project's records) is not clear to me enough.

我应该将使用项目的处理程序添加到库主记录器中吗?

Am I supposed to add my using project's handlers into the library main logger?

推荐答案

NullHandler添加到库的顶级记录器中,并且在您的应用程序中,只需将处理程序添加到根记录器中(假设这两个库都没有从其记录器中关闭propagate标志).然后,对记录到这两个库的任何调用都应传递给根记录器中的处理程序.

Add a NullHandler to the top level logger of your library, and in your application, you'll just need to add handlers to the root logger (assuming that neither library has turned the propagate flag off from their loggers). Any calls made to log to either library should then be passed to the handlers in the root logger.

此图说明了数据如何流过日志记录系统.根记录器是系统中所有记录器的祖先.

This diagram illustrates how data flows through the logging system. The root logger is an ancestor to all loggers in the system.

这篇关于将库的NullHandler集成到我自己的项目记录器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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