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

naman jain namanvit at gmail.com
Fri Nov 6 00:58:32 MST 2009


Thanks. that does the job for me very well.

On Thu, Nov 5, 2009 at 7:18 PM, <exarkun at twistedmatrix.com> wrote:

> 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
> >the
> >console.
> >print("goes in both") -> the log also gets this and the console also.
> >
> >Thanks
>
> How about installing two log observers?
>
>    from sys import stdout
>    from twisted.python.log import FileLogObserver, startLogging,
> addObserver, msg
>
>    # First, startLogging to capture stdout
>    startLogging(stdout)
>
>    # Now add an observer that logs to a file
>    addObserver(FileLogObserver(file("foo.log")).emit)
>
>    msg("Hello, world")
>    print "Goodbye, world"
>
> Jean-Paul
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20091106/d47707d9/attachment-0001.html>


More information about the Twisted-Python mailing list