Commit a634f5ce by Őry Máté

agent-winservice: add file logging

parent 035f93af
import win32serviceutil import logging
import win32service import os
import win32event
import servicemanager import servicemanager
import socket import socket
import win32event
import win32service
import win32serviceutil
from agent import main as agent_main, reactor from agent import main as agent_main, reactor
logger = logging.getLogger()
fh = logging.FileHandler(
os.path.join(os.path.dirname(__file__), "agent-service.log"))
formatter = logging.Formatter(
"%(asctime)s - %(name)s [%(levelname)s] %(message)s")
fh.setFormatter(formatter)
logger.addHandler(fh)
logger.info("%s loaded", __file__)
class AppServerSvc (win32serviceutil.ServiceFramework): class AppServerSvc (win32serviceutil.ServiceFramework):
_svc_name_ = "circle-agent" _svc_name_ = "circle-agent"
...@@ -20,11 +31,13 @@ class AppServerSvc (win32serviceutil.ServiceFramework): ...@@ -20,11 +31,13 @@ class AppServerSvc (win32serviceutil.ServiceFramework):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop) win32event.SetEvent(self.hWaitStop)
reactor.stop() reactor.stop()
logger.info("%s stopped", __file__)
def SvcDoRun(self): def SvcDoRun(self):
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED, servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_, '')) (self._svc_name_, ''))
logger.info("%s starting", __file__)
agent_main() agent_main()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment