Tuesday, 15 June 2010

Python logging module doesn't work within installed windows service -



Python logging module doesn't work within installed windows service -

why calls logging framework within python service not produce output log (file, stdout,...)?

my python service has general form:

import logging logger = logging.getlogger() logger.setlevel(logging.debug) fh = logging.filehandler('out.log') logger.addhandler(fh) logger.error("outside") class service (win32serviceutil.serviceframework): _svc_name_ = "example" _svc_display_name_ = "example" _svc_description_ = "example" def __init__(self,args): logger.error("not logged") win32serviceutil.serviceframework.__init__(self,args) self.hwaitstop = win32event.createevent(none,0,0,none) servicemanager.logmsg(servicemanager.eventlog_information_type, servicemanager.pys_service_started, (self._svc_name_,'')) def svcstop(self): self.reportservicestatus(win32service.service_stop_pending) win32event.setevent(self.hwaitstop) self.stop = true def svcdorun(self): self.reportservicestatus(win32service.service_running) self.main() def main(self): # service logic logger.error("not logged either") pass

the first phone call logger.error produces output, not 2 within service class (even after installing service , making sure running).

i've found logging within actual service loop works logging module , log file ends in c:\python27\lib\site-packages\win32.

i abandoned logging logging module windows didn't seem effective. instead started utilize windows logging service, e.g. servicemanager.loginfomsg() , related functions. logs events windows application log, can find in event viewer (start->run->event viewer, windows logs folder, application log).

python logging windows-services pywin32

No comments:

Post a Comment