Tweaking Zope Event Log

Sometimes, you encounter a strange bug on a running server and you wish to change the log level.

C:\Zope275>bin\python lib/python/ZServer/...
  medusa/monitor_client_win32.py localhost 7099
>>> import logging
>>> e = logging.getLogger('event')
>>> print e.level
20
>>> print [h.level for h in e.handlers]  # what are the handlers logging at?
[5, 25]
>>> # handler 0 effectively logs at level 20, because e.getEffectiveLevel() == 20
>>> e.setLevel(0)
>>> from zLOG import LOG, TRACE
>>> LOG('Test Module', TRACE, 'Test Message') # 'Test message'
... should appear in the log file

There are two kinds of levels in the zope.conf. One is the logger level, and the other is the log-handlers level. These levels mean different things. The logger level actually specifies a filter for the child log-handlers, and would have been more appropriate to name it minimum-level. Confused? Here is an example:

<eventlog>
  # eventlog.level defaults to info.
  # uncomment below for expected behaviour
  # level all
  <timedrotatinglogfile>
    level all
    path $INSTANCE/log/event.log
    when D
  </timedrotatinglogfile>
  <email-notifier>
    level error
    from XXX
    to XXX
    smtp-server XXX
  </email-notifier>
</eventlog>

In the case above, event log has a logger-level of info, while timedrotatinglogfile has a loghandler-level of all. Effectively, timedrotatinglogfile will not log at level=all at all, as the event log level specifies that only logs of level info or greater will be recorded. Setting timedrotatinglogfile level to “all” does not override eventlog setting.

Leave a Reply