[Twisted-Python] Need for multiple loggers...

Moof moof at metamoof.net
Sat Jun 10 12:45:15 EDT 2006


On 6/10/06, Chaz. <eprparadocs at gmail.com> wrote:
> Thanks but I think that answers the wrong question. In my original
> application I have three different named loggers (the original app
> is written in Python). I have logOp, logTrace, logDebug each of which
> goes somewhere different (for instance logOp messages go to the
> operators system, logDebug is sent to a non-rotated file and logTrace
> goes to a rotating log file). Through out my application I will log
> message to the appropriate logger, for example messages that I want
> written out to the debug file I write as logDebug.msg(...). Those that I
> want to trace objects moving around I will do logDebug.info(...). etc.
>
> In Twisted.python.log it looks like there is a single logger and I do:
> log.startLogging(...). What I need to know is how can I create three
> different loggers in my new application. Do I need to subclass some
> twisted class?

The twisted log system has a single "log publisher", known as
twisted.python.log.theLogPublisher. This publisher will receive all
log messages and add certain essential informaion, and create
something called an eventDict. It then passes all eventDict to every
LogObserver registered with it. This allows for a central location to
receive log messages that decouples potentially slow, blocking, file
writing or network sending of log messages from the rest of the
asynchronous framework.

log.StartLogging(file) literally creates a FileLogObeserver for the
file called flo, and then calls StartLoggignWithObserver(flo.emit).

You want to create an equivalent to a FileLogObserver, or just
subclass it. You can chose to ignore certain messages by checking for
flags in the eventDict, and just returning from the method, or you can
write it to a file, or send it over the network or whatever.

Moof




More information about the Twisted-Python mailing list