[Twisted-Python] Windows NT Service Problem
Chris Mellon
arkanes at gmail.com
Fri May 18 10:02:16 EDT 2007
On 5/18/07, Werner Thie <wthie at thiengineering.ch> wrote:
> May I chime in with a question:
>
> Is there a decent way to redirect twisted logging to the system/app log
> facilities of MSW?
>
It's trivial to write a log observer that does so. Below is a snippet
from my app that writes errors (logged with log.err) to the win32
event log. The servicemanager module is part of pywin32.
import servicemanager
def ErrorLogger(msg):
""" A log observer which will write error messages
to the windows event log
Usage: log.addObserver(ErrorLogger)
"""
if not "isError" in msg:
return
if not msg["isError"]:
return
#the value is sometimes (often? always?) a tuple
messages = list(msg["message"])
if "failure" in msg:
thisFailure = msg["failure"]
messages.append(thisFailure.getTraceback(detail="verbose"))
message = '\n'.join(str(l) for l in messages)
servicemanager.LogErrorMsg(message)
More information about the Twisted-Python
mailing list