[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: python logging writes an empty file

Ovidiu Deac

3/26/2010 4:26:00 PM

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 with
logging.config.fileConfig() ?
2 Answers

Vinay Sajip

3/26/2010 7:09:00 PM

0

On Mar 26, 4:26 pm, Ovidiu Deac <ovidiud...@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

Ovidiu Deac

3/26/2010 8:08:00 PM

0

It worked. Setting disable_existing_loggers=False fixed my problem.

Thanks to both of you!
Ovidiu

On Fri, Mar 26, 2010 at 9:09 PM, Vinay Sajip <vinay_sajip@yahoo.co.uk> wrote:
> On Mar 26, 4:26 pm, Ovidiu Deac <ovidiud...@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
> --
> http://mail.python.org/mailman/listinfo/p...
>