[Twisted-Python] Logging to both console and file (using twisted logging API)?

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Thu Nov 5 13:18:16 EST 2009

On 01:20 pm, namanvit at gmail.com wrote:
>I ll try to rephrase it better:
>I simply want the print statement to appear in both the log file and 
>print("goes in both") -> the log also gets this and the console also.

How about installing two log observers?

    from sys import stdout
    from twisted.python.log import FileLogObserver, startLogging, 
addObserver, msg

    # First, startLogging to capture stdout

    # Now add an observer that logs to a file

    msg("Hello, world")
    print "Goodbye, world"


More information about the Twisted-Python mailing list