PEP 282: A Logging System -- comments please

Edward K. Ream edream at tds.net
Fri Mar 8 18:50:04 EST 2002


PEP 282 is more complex and less flexible than it could be.  Instead,
Python's standard logging system could well use dynamic tracing.  

Consider a tracing function with two arguments, a "tracepoint" string
and a message (or function to execute).  By default, the trace function
uses the name of the method from which trace was called as the
tracepoint string, so,

def foo():
  trace("abc")

is the same as:

def foo():
  trace("foo","abc")

This trace prints "foo:abc" only if tracing for "foo" is enabled. 
trace(f) executes f() if "foo" is enabled.  Extending this scheme is
easy.

The app (or tracing object) maintains a dict of enabled tracepoint
names. The user can add or delete entries in the dict at run time. 
trace() supports wildcards and other special characters, so enable("*")
enables all tracing, enable("level2.?") enables "level 2" tracing,
trace("-foo","abc") suppresses wildcard matches for "foo", etc.

Dynamic tracing is trivial to implement.  More importantly, it is
simpler to use and more flexible than any static scheme such as the one
described in 282.

PEP 282 talks about control flow, levels, loggers, handlers, formatters,
filters and configuration.  A case can be made for dealing with each
issue, and experience shows that simple dynamic tracing suffices in
complex apps like compilers and file systems.  For example, all kinds of
configuration (including picking formatters, data sinks, altering the
flow of control of the program being run, etc.) can be done just by
initializing the dict of tracepoint names.

Dynamic tracing provides the essential benefit of any logging system,
namely the ability to alter tracing output without altering the program
being traced.  It does so in the simplest and most general way.

Edward
--------------------------------------------------------------------
Edward K. Ream   email:  edream at tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html
--------------------------------------------------------------------



More information about the Python-list mailing list