Improve logging with "filters"
|Reported by:||Pedro Algarvio, aka, s0undt3ch <ufs@…>||Owned by:||rblank|
Here's a suggestion for an improvement on trac's logging.
First of all, this change is backwards compatible with the old way trac handled it's logging.
What I suggest is some more explicit module names, ie, full dotted module path, because, web_ui ain't that explicit, right? trac itself has several of those; and the ability to filter what modules we really want logging from.
This will help debugging parts of trac and also plugin development.
This change introduces a new config variable under [logging], log_filters and it's syntax is:
[logging] log_filters = trac:ERROR, my.plugin:DEBUG
What the above means is:
- all logging messages that come from a module that starts with trac(trac.web, trac.ticket, tracforge, etc) and which it's level is higher that ERROR are logged and shown to the user;
- all logging messages that come from a module that starts with my.plugin and which it's level is higher than DEBUG are also logged.
- all other messages that do not match the above "filters" and which their logging level is higher than what's defined on log_level will be shown to the user.
This will also simplify logging for plugin' development. Currently if our class is inheriting from Component we have access to logging on self.log. If our class is not inheriting from Component we have to pass env and access logging from env.log. What this change introduces is the ability to do, from anywhere:
import logging log = logging.getLogger(__name__)
We're now able to log just by calling log.
There's only one catch on the above code. At least the root logger must be configured to be able to log, ie, adding the above code to genshi/__init__.py won't work because genshi is called prior to the logging has been setup, but that's it.
Note that regarding trac, there won't be any issues because, environment is the first thing being initialized and it calls the function to setup logging at an early stage.
Now you ask, why did he talked about genshi!?
Well, with this change, and how logging is configured, we can access logging from trac, it's plugins and packages trac uses, like genshi.
Hope the code is good enough.
Change History (29)
Changed 4 years ago by palgarvio
comment:16 Changed 3 years ago by rblank
- Milestone changed from triaging to 0.13
- Owner changed from jonas to rblank