I'm trying to perform some logging from external methods. I've discovered that, if you're not careful, you get more and more loggers each time Zope reloads the module. This leads to an ever-increasing number of identical entries in the log file, whose timestamps all match down to the millisecond.

Currently, thanks to the helpful folks on python-list, I've got it down to two entries per time. My goal is to get exactly one log entry per event logged :)

Here's the code I'm using in an external module. I set up a global _logger instance that various methods in the module use:

import logging
_logger = logging.getLogger("lois.access")
if not _logger.handlers:
    _handler = logging.FileHandler(os.path.join(LOG_ROOT, 'access.log'))
_formatter = logging.Formatter("%(asctime)s %(name)s %(levelname)s: %(message)s")
_logger.propagate = 0

Each time a method calls _logger.info("some event"), I get duplicate entries, like so:

2006-03-31 15:07:57,676 lois.access INFO: get wiki_ldap 0.html  (jedp)
2006-03-31 15:07:57,676 lois.access INFO: get wiki_ldap 0.html  (jedp)

The _logger.handlers test is there to make sure I don't spawn a new handler each time the module gets reloaded. This makes a huge difference; without it, the number of duplicates grows and grows.

Can anyone tell me how to get a logger to leave just one log entry from an external module?

Many thanks.  In perplexity,

Jed Parsons       Industrial Light + Magic  (415) 746-2974
"++,++2-27,280,481=1-7.1++2,800+++2,8310/1+4131+1++2,80\0.  What!?")));
Zope maillist  -  Zope@zope.org
**   No cross posts or HTML encoding!  **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to