By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,630 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,630 IT Pros & Developers. It's quick & easy.

logging and propagation

P: n/a
oj
Hi,

I want to setup logging with 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.
Nov 21 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
oj <oj*****@gmail.comwrites:
Hi,

I want to setup logging with 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.
Loggers have a "propagate" attribute. If you set this to False in the
child then you should get what you want I think.
Nov 21 '07 #2

P: n/a
oj
On Nov 21, 11:48 am, Paul Rudin <paul.nos...@rudin.co.ukwrote:
oj <ojee...@gmail.comwrites:
Hi,
I want to setup logging with 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.

Loggers have a "propagate" attribute. If you set this to False in the
child then you should get what you want I think.
No, because I want message to propagate usually. There are only
specific instances when I don't want it to propagate.
Nov 21 '07 #3

P: n/a
oj <oj*****@gmail.comwrites:
On Nov 21, 11:48 am, Paul Rudin <paul.nos...@rudin.co.ukwrote:
>Loggers have a "propagate" attribute. If you set this to False in the
child then you should get what you want I think.

No, because I want message to propagate usually. There are only
specific instances when I don't want it to propagate.
Can't you set propagate to False during those specific instances and 1
the rest of the time?
Nov 21 '07 #4

P: n/a
Paul Rudin wrote:
oj <oj*****@gmail.comwrites:
>On Nov 21, 11:48 am, Paul Rudin <paul.nos...@rudin.co.ukwrote:
>>Loggers have a "propagate" attribute. If you set this to False in the
child then you should get what you want I think.

No, because I want message to propagate usually. There are only
specific instances when I don't want it to propagate.

Can't you set propagate to False during those specific instances and 1
the rest of the time?
That calls for concurrency-issues, doesn't it?

I think he will have to go down the subclass-route.

Diez
Nov 21 '07 #5

P: n/a
On Nov 21, 11:38 am, oj <ojee...@gmail.comwrote:
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?
Nov 22 '07 #6

P: n/a
oj
On Nov 22, 5:44 am, Vinay Sajip <vinay_sa...@yahoo.co.ukwrote:
On Nov 21, 11:38 am, oj <ojee...@gmail.comwrote:
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.
Nov 22 '07 #7

P: n/a
On Nov 22, 9:18 am, oj <ojee...@gmail.comwrote:
On Nov 22, 5:44 am, Vinay Sajip <vinay_sa...@yahoo.co.ukwrote:
On Nov 21, 11:38 am, oj <ojee...@gmail.comwrote:
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?
Nov 22 '07 #8

P: n/a
On Nov 22, 2:34 pm, Vinay Sajip <vinay_sa...@yahoo.co.ukwrote:
On Nov 22, 9:18 am, oj <ojee...@gmail.comwrote:

Why not apply the same filter to the parent loggers?
Of course, you can apply filters at the loggers or the handlers. The
filters at the logger are checked first. If they pass, then the event
is handled - and filters at the handlers get to participate.
Nov 22 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.