[Python-Dev] PEP 282: A Logging System -- comments please

Trent Mick trentm at ActiveState.com
Mon Feb 18 12:55:02 EST 2002


[Michael McLay]
> I scanned the PEP and didn't find a reference to the logging package 
> supporting logging over a network. 


[Greg Ward]
> I think the right way to handle that would be to pass a file-like object
> to the logging framework, which it then write()'s to.  That should work
> just fine for stream (TCP) sockets; I *think* it would work for datagram
> (UDP) sockets too, but I'd want to test it first.


[Fred Drake]
> It seems to me that it should be trivial to map from the
> logging API to syslog; it already provides for logging to
> remote systems as well as filtering.
> 
> I'm sure this is already hashed out in the PEP though, so I
> should be reading that instead of commenting here.  ;-)


The current plan is that you can subclass class Handler for this.
Generally a subclass will have this basic API to work with:
    class Handler:
        def __init__(self):
            # initialize you socket or whatever here
        def publish(self, logRecord):
            # write your log record here
        def flush(self):
            # flush file or socket, flush buffered output to syslog backend,
            # etc.
        def close(self):
            # cleanup
c.f. http://java.sun.com/j2se/1.4/docs/api/java/util/logging/Handler.html

>From the PEP:
>     More standard Handlers may be implemented if deemed desirable and
>     feasible.  Other interesting candidates:
> 
>         - SocketHandler: A handler for writing to remote TCP ports.
>         - CreosoteHandler: A handler for writing to UDP packets, for
>           low-cost logging.  Jeff Bauer already had such a system [5].
>         - MemoryHandler: A handler that buffers log records in memory
>           (JSR047).
>         - SMTPHandler: Akin to log4j's SMTPAppender.
>         - SyslogHandler: Akin to log4j's SyslogAppender.
>         - NTEventLogHandler: Akin to log4j's NTEventLogAppender.



Trent

-- 
Trent Mick
TrentM at ActiveState.com




More information about the Python-list mailing list