Re: [Zope] logging from external methods

2006-04-02 Thread Dieter Maurer
Jed Parsons wrote at 2006-3-31 15:28 -0800:

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.

Hm... Looks like a bug in Python's logging:

  You should not get duplicate log entries when you
  happen to instantiate several logger objects (but use a single one).

That said: most similar problems with External Methods can
be solved by putting things in a true Python module and
import it in the External Method.

-- 
Dieter
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] logging from external methods

2006-04-02 Thread Stefan H. Holek
Note that ExternalMethods are not, and do not behave like, python  
modules.


Stefan

On 1. Apr 2006, at 01:28, Jed Parsons wrote:

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.


--
Anything that happens, happens.  --Douglas Adams


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] logging from external methods

2006-03-31 Thread Jed Parsons


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!?)));
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )