python logging writes an empty file

Vinay Sajip vinay_sajip at yahoo.co.uk
Fri Mar 26 15:09:10 EDT 2010


On Mar 26, 4:26 pm, Ovidiu Deac <ovidiud... at gmail.com> wrote:
> Anyway, thanks for the first part.
>
> Anybody else has any idea why using the same configuration file works
> when running the tests with nosetests and doesn't work withlogging.config.fileConfig() ?

It's probably because the fileConfig code is intended to *replace* any
existing configuration. This means disabling any existing loggers
which are not named explicitly, or not descendants of loggers named
explicitly, in the configuration.

Make sure you call logging.config.fileConfig() before any loggers have
been instantiated in your code, or else ensure that all the top-level
parents of those loggers (i.e. just below the root logger) are defined
in the configuration.

If you have version 2.6 or newer of Python, the fileConfig call has an
optional keyword parameter disable_existing_loggers which has a
default value of True, but which you can set to False to avoid
disabling the existing loggers.

Regards,

Vinay Sajip



More information about the Python-list mailing list