[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

Jean-Michel Pichavant

3/26/2010 1:53:00 PM

Ovidiu Deac wrote:
> Then I tried this:
> file = logging.FileHandler(logFileBasename, 'w')
> file.setLevel(logging.INFO)
> # set a format which is simpler for console use
> formatter = logging.Formatter('%(asctime)s %(name)-12s
> %(levelname)-8s %(message)s',)
> # tell the handler to use this format
> file.setFormatter(formatter)
> # add the handler to the root logger
> logging.getLogger('').addHandler(file)
> logging.getLogger('')
>
> ...which also leaves my output file EMPTY.
>
> I'm out of ideas. Can anybody help me with this?
>
> Thanks in advance!
> ovidiu
>
You set le level of your handler, but did not set the level of the
logger itself.
Replace file.setLevel(logging.INFO) by
logging.getLogger().setLevel(logging.INFO)

Log events are matched versus the logger level 1st, then the handler
level (if applicable). Most of the time you don't need to tune your
handler levels.

JM