Logger is now configured correctly via file, requested operation is now logged at `info`

This commit is contained in:
Mauro Mugnaini 2023-04-17 17:32:47 +02:00
parent 265bfa2b5c
commit 6045063476
1 changed files with 9 additions and 4 deletions

View File

@ -34,14 +34,20 @@ class PyExec():
self.cfg = configparser.ConfigParser()
self.cfg.read(config)
self.workerid = self.cfg["common"].get("workerid", "pythonworker-" + str(random.randint(1000,10000)))
logging.config.fileConfig(self.cfg["common"].get("loggerconfig", "logging-docker.cfg"))
loggerconfigfile = self.cfg["common"].get("loggerconfig", "logging-docker.cfg")
print("Loading logger configuration from: " + loggerconfigfile)
logging.config.fileConfig(loggerconfigfile, disable_existing_loggers=False)
self.logger = logging.getLogger("pyexec")
self.logger.info("Initializing PyExec worker %s with config.cfg", self.workerid)
self.threads = self.cfg["common"].getint("threads", 3)
self.pollrate = self.cfg["common"].getfloat("pollrate", .1)
self.server = os.environ.get('CONDUCTOR_SERVER', self.cfg["common"].get("server", "http://localhost:8080/api"))
self.auth = os.environ.get('CONDUCTOR_WORKER_AUTH', self.cfg["common"].get("auth"))
# if self.auth is None:
# error = "Unable to find auth details neither in ENV nor in config file"
# self.logger.critical(error)
# raise Exception(error)
for plg in pluginlist:
path = "pyexecplugins." + plg
try:
@ -80,7 +86,7 @@ class PyExec():
# Get operation from input or task type (in case of standalone tasks) fallback to Nop
operation = task["inputData"].get("operation") or task["taskDefName"] or "Nop"
self.logger.debug("Operation is %s", operation)
self.logger.info("Operation is %s", operation)
# Get plugin by checking either name or alias (in case of standalone tasks the task type is aliased to the plugin name)
p = PyExecPlugin.get(operation) or PyExecPlugin.getAlias(operation)
@ -89,7 +95,6 @@ class PyExec():
if p != None:
pi = p(task["inputData"], self.cfg)
ret = pi.execute()
else: raise Exception("Operation {} not found.".format(operation))
return { "status" : "COMPLETED", "output" : ret, "logs" : ["one","two"]}