[Twisted-Python] Controlling twisted logging
Eric Mangold
teratorn at twistedmatrix.com
Wed Dec 1 21:10:23 EST 2004
Norm Petterson wrote:
> Hello,
>
> Having just spent some time trying to "turn off" twisted logging via
> log.discardLogs() and/or log.startLogging(log.NullFile()) in a twisted
> app
> that initially logs to an actual file, it seems that
> log.startLogging(log.NullFile()) only works as expected if no previous
> startLogging call using a valid file object has been made. Otherwise,
> messages continue to be logged.
It seems the best documentation is the source!
startLogging will create a FileLogObserver that wraps the passed in
file-object. The "emit"
method of that FileLogObserver gets added to the *list* of observers.
So startLogging does not stop things being logged to files that you passed
in
on previous calls to startLogging.
If you want to be able to start logging on a given file then you need to
be more explicit
about what objects are getting created. For example:
(untested)
flo = FileLogObserver(file)
startLoggingWithObserver(flo.emit)
then later you can do, e.g.
flo.stop()
then later
flo.start()
> Is this observation correct, or am I overlooking some way to enable
> logging
> to a logfile and subsequently disable it?
Looks like correct behavior to me.
> In my above experiments,
> log.discardLogs() seemed to have no effect either once valid file logging
> had been initiated with log.startLogging.
Yeah, have a glace at the implementation of discardLogs()
-Eric
More information about the Twisted-Python
mailing list