> On Nov 9, 2015, at 2:29 PM, Kevin Mcintyre <kebi...@gmail.com> wrote:
>
> http://twistedmatrix.com/documents/current/core/howto/logger.html
> <http://twistedmatrix.com/documents/current/core/howto/logger.html>
>
> I'm looking at the new-ish logger api and wonder how to log to console as a
> first step to transitioning.
>
> Any pointers? Thanks.
Do you mean "emit structured log text to stdout"? In that case, that is
covered in the document you link to; these two sections:
http://twistedmatrix.com/documents/current/core/howto/logger.html#avoid-mutable-event-keys
http://twistedmatrix.com/documents/current/core/howto/logger.html#starting-the-global-log-publisher
create a jsonFileLogObserver and start logging to it:
import sys
from twisted.logger import jsonFileLogObserver, globalLogBeginner, Logger
globalLogBeginner.beginLoggingTo([jsonFileLogObserver(sys.stdout)])
log = Logger()
log.info("Information.")
If you want unstructured log output for human reading (not a good choice for an
automated system, but perhaps useful for debugging), you can instead go with
textFileLogObserver, in almost exactly the same way:
import sys
from twisted.logger import textFileLogObserver, globalLogBeginner, Logger
globalLogBeginner.beginLoggingTo([textFileLogObserver(sys.stdout)])
log = Logger()
log.info("Information.")
Is this what you were looking for?
-glyph
_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python