質問

I have an application foo which iterates over entry points using a group named foo.modules . Then it loads any occurrences using the load() method. This architecture allows writing plugins/modules for the application foo and can be found in more details here.

Also, the application configures some logging handlers when it starts. When I load the plugins however (let's say foo_plugin), the logging namespace of the foo application is not available in the namespace hierarchy, which leads to warnings like these:

No handlers could be found for logger "foo_plugin.plugin"

The concept is that whoever writes a plugin can just write:

import logging
logger = logging.getLogger(__name__)

and the plugin logging should work as the foo application dictates.

If I explicitly prepend the foo namespace (foo.) before the __name__ variable, the logging works again, but this is not very elegant of course. Any better ideas?

役に立ちましたか?

解決

How is the plugin supposed to know whether it's part of application foo as opposed to application bar? If you don't want your plugins to be part of the foo namespace, you can just attach your handlers to the root logger and you won't get the message about "no handlers could be found".

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top