Logger / I get all messages 2 times

Vinay Sajip vinay_sajip at yahoo.co.uk
Fri Oct 24 10:09:24 EDT 2008


On Oct 24, 8:28 am, ASh <anton.shish... at gmail.com> wrote:
> On Oct 23, 5:10 pm, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
>
>
>
> > ASh wrote:
> > > Hi,
>
> > > I have this source:
>
> > > importlogging
> > > importlogging.config
>
> > >logging.config.fileConfig("logging.properties")
> > > log =logging.getLogger("qname")
> > > log.debug("message")
>
> > > ------------------- OUTPUT
> > > DEBUG logger_test:8:  message
> > > DEBUG logger_test:8:  message
>
> > > ------- FILE CONFIG
> > > [formatters]
> > > keys: detailed
>
> > > [handlers]
> > > keys: console
>
> > > [loggers]
> > > keys: root, engine
>
> > > [formatter_detailed]
> > > format: %(levelname)s %(module)s:%(lineno)d:  %(message)s
>
> > > [handler_console]
> > > class: StreamHandler
> > > args: []
> > > formatter: detailed
>
> > > [logger_root]
> > > level: ERROR
> > > handlers: console
>
> > > [logger_engine]
> > > level: DEBUG
> > > qualname: qname
> > > handlers: console
>
> > > ---------------
>
> > > Why do I get the log 2 times?
>
> > Because you add the handler "console" two times, to logger_engine and
> > logger_root. You should only add it to root, or set propagate to false.
>
> > Diez
>
> What if I want to output only the specific logger to console and
> ignore every other?

Just add the handler to the logger you want and to no other logger.
Then, events logged with the logger you want (and its child loggers)
will be sent to the console. If you don't want the child loggers to
log to console, set their propagate value to 0.

Regards,

Vinay Sajip



More information about the Python-list mailing list