logging and propagation

Vinay Sajip vinay_sajip at yahoo.co.uk
Thu Nov 22 09:34:28 EST 2007


On Nov 22, 9:18 am, oj <ojee... at gmail.com> wrote:
> On Nov 22, 5:44 am, Vinay Sajip <vinay_sa... at yahoo.co.uk> wrote:
>
>
>
> > On Nov 21, 11:38 am, oj <ojee... at gmail.com> wrote:
>
> > > Hi,
>
> > > I want to setuploggingwith two loggers:
>
> > > The child logger is used when something different needs to be done
> > > with the log record, and the log record will propagate and be logged
> > > by the root logger as usual.
>
> > > However, there are certain times when I don't want a log record to
> > > propagate from the child to the parent.
>
> > > I don't really want to add a filter to the root logger, as it should
> > > be up to the child whether the record propagates or not.
>
> > > I've tried setting the child to a lower level then the parent, but if
> > > a record is dealt with by the child, the parent deals with it anyway
> > > regardless of its own log level.
>
> > > Also, filters only apply particular handlers and do not affect
> > > propagation.
>
> > > Can anyone suggest a simple way to achieve this?
>
> > > Currently, the only thing I can think of, is overriding the
> > > callHandlers method in a custom Logger class.
>
> > Do you already have a Logger subclass? Where and when is the decision
> > being made about whether to propagate or not?
>
> The decision is being made in a filter. Certain log records are dealt
> with differently from there.
>
> The filter also prevents the handler from dealing with those log
> records, but it doesn't stop the handlers of parent loggers dealing
> with them.

Why not apply the same filter to the parent loggers?



More information about the Python-list mailing list