vinay_sajip at yahoo.co.uk
Sun Jun 4 14:23:55 CEST 2006
> Consider the following scenario: root is CRITICAL, l01 is DEBUG, a debug
> message is logged on l01. l01 decides that the message should be
> printed, and _both_ root and l01 print it. Now, it is good that the
> message is propagated to root, but why doesn't root decide for itself
> whether to print it or not?
It's not propagated to the root logger (or to ancestor loggers in
general) - just to the handlers associated with ancestor loggers.
> For instance, I log root to syslog and have only critical messages
> there. I log l01 to console to debug. I want that my message to l01 is
> not printed by root since its level is CRITICAL. This is why I want that
> each logger re-evaluates the message level for itself. Could you perhaps
> give a useful example why one could want loggers to decide once?
You can set levels on handlers as well as loggers. So if you add a
syslog handler to the root and set its level to CRITICAL, only CRITICAL
messages are sent to syslog.
> And another thing I couldn't find how to do: I want to have several
> debug levels. I can log messages without problems, but numeric values in
> the configuration file cause error messages during
> logging.config.fileConfig. Can I specify numeric values in the config
You should use addLevelName to add custom levels. You can do e.g.
logging.MYCUSTOMLEVEL = 25
and then reference MYCUSTOMLEVEL in the config file.
More information about the Python-list