[Zope] logging from external methods
Jed Parsons
jedp at ilm.com
Fri Mar 31 18:28:50 EST 2006
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")
_logger.setLevel(logging.DEBUG)
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")
_handler.setFormatter(_formatter)
_logger.addHandler(_handler)
_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,
j
--
Jed Parsons Industrial Light + Magic (415) 746-2974
grep(do{for(ord){(!$_&&print"$s\n")||(($O+=(($_-1)%6+1)and
grep(vec($s,$O++,1)=1,1..int(($_-6*6-1)/6))))}},(split(//,
"++,++2-27,280,481=1-7.1++2,800+++2,8310/1+4131+1++2,80\0. What!?")));
More information about the Zope
mailing list