fix logging again

This commit is contained in:
2020-11-09 15:39:08 +01:00
parent c26f5c92eb
commit 4815480361

View File

@@ -32,12 +32,13 @@ from uuid import uuid4
class SchedulerLogger(logging.LoggerAdapter): class SchedulerLogger(logging.LoggerAdapter):
def process(self, msg, **kwargs): def process(self, msg, kwargs):
if "event" in kwargs: if "event" in self.extra:
event = kwargs["event"] event = self.extra["event"]
msg = f"{msg}, mask={event.maskname}, path={event.pathname}" msg = f"{msg}, mask={event.maskname}, path={event.pathname}"
if "id" in kwargs:
task_id = kwargs["id"] if "id" in self.extra:
task_id = self.extra["id"]
msg = f"{msg}, task_id={task_id}" msg = f"{msg}, task_id={task_id}"
return msg, kwargs return msg, kwargs
@@ -104,29 +105,25 @@ class TaskScheduler:
self._log.info("all remainig tasks completed") self._log.info("all remainig tasks completed")
async def _run_job(self, event, task_state, restart=False): async def _run_job(self, event, task_state, restart=False):
logger = SchedulerLogger(self._log, {
"event": event,
"id": task_state.id})
if self._delay > 0: if self._delay > 0:
task_state.task = self._loop.create_task( task_state.task = self._loop.create_task(
asyncio.sleep(self._delay, loop=self._loop)) asyncio.sleep(self._delay, loop=self._loop))
logger = SchedulerLogger(self._log, {
"event": event,
"id": task_state.id,
"delay": self._delay})
try: try:
if restart: if restart:
prefix = "re-" prefix = "re-"
else: else:
prefix = "" prefix = ""
logger.info(f"{prefix}schedule task") logger.info(f"{prefix}schedule task, delay={self._delay}")
await task_state.task await task_state.task
except asyncio.CancelledError: except asyncio.CancelledError:
return return
logger = SchedulerLogger(self._log, {
"event": event,
"id": task_state.id})
logger.info("start task") logger.info("start task")
task_state.task = self._loop.create_task( task_state.task = self._loop.create_task(
@@ -378,7 +375,7 @@ class FileManagerScheduler(TaskScheduler):
f"unable to {rule.action} '{path}', " f"unable to {rule.action} '{path}', "
f"resulting destination path is empty") f"resulting destination path is empty")
if os.path.exists(dst) and not self.overwrite: if os.path.exists(dst) and not rule.overwrite:
raise RuntimeError( raise RuntimeError(
f"unable to {rule.action} file from '{path} " f"unable to {rule.action} file from '{path} "
f"to '{dst}', destination path exists already") f"to '{dst}', destination path exists already")