Logging to different addressees

McA andreas.mock at web.de
Wed Jul 16 09:55:55 CEST 2008

Hi Vinay,

thank you for being so patient.

On 16 Jul., 01:21, Vinay Sajip <vinay_sa... at yahoo.co.uk> wrote:
> On Jul 15, 5:17 pm, McA <andreas.m... at web.de> wrote:
> > > If you added the admin sink handler to the root logger, you're done.
> > Isn't that the first thing above? What do you mean?
> I gave you a choice - to add the handler to the admin_logger OR the
> root logger. So I am saying here that if you added to the root logger
> (and not common_logger, assuming they're different), then there's
> nothing more to do...

Reading the rest of your mail let me understand what you meant.

> # simple.py
> import logging
> admin_logger = logging.getLogger("") # The root logger
> addressee_logger = logging.getLogger("addressee")
> admin_sink = logging.FileHandler("admin.log", "w")
> addressee_sink = logging.FileHandler("addressee.log", "w")
> admin_logger.addHandler(admin_sink)
> addressee_logger.addHandler(addressee_sink)
> admin_logger.setLevel(logging.DEBUG)
> admin_logger.debug("This message appears in admin sink only.")
> addressee_logger.debug("This message appears in both admin sink and
> addressee sink."

Thank you for that snippet. That means, that the root-logger does
EVERY message (if it fits to the level and isn't filtered) and the
inheritage chain is build by the chosen logger names, e.g.
messages to logging.getLogger('tree.leave') would also show up in
logging.getLogger('tree') automatically?

If this is true, how can I avoid this "bubbling up" if I would like
(You see, that's a new question, but I want to take the chance to get
the answers from you personally ;-)

Hope not to bother.

Best regards
Andreas Mock

More information about the Python-list mailing list