From 0b8e32fe5392f64d6ef2af7df7776e3fd68bc3af Mon Sep 17 00:00:00 2001 From: Thomas Oettli Date: Wed, 4 Nov 2020 23:58:52 +0100 Subject: [PATCH] improve logging again --- README.md | 6 +++--- pyinotifyd/__init__.py | 4 ++-- pyinotifyd/filemanager.py | 2 +- pyinotifyd/scheduler.py | 9 ++++----- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index dc433b8..38b296c 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ rule = Rule( fm = FileManager( rules=[rule], - logname="FileManager") + logname="filemanager") ``` FileManager provides a task **fm.task**. @@ -60,7 +60,7 @@ s = TaskScheduler( files=True, dirs=False, delay=0, - logname="TaskScheduler") + logname="scheduler") ``` TaskScheduler provides two tasks which can be bound to an event in an event map. * **s.schedule** @@ -115,7 +115,7 @@ pyinotifyd expects an instance of Pyinotifyd named **pyinotifyd** defined in the pyinotifyd = Pyinotifyd( watches=[watch], shutdown_timeout=30, - logname="Pyinotifyd") + logname="daemon") ``` ### Logging diff --git a/pyinotifyd/__init__.py b/pyinotifyd/__init__.py index 67b94ab..ec25cfc 100755 --- a/pyinotifyd/__init__.py +++ b/pyinotifyd/__init__.py @@ -33,10 +33,10 @@ from pyinotifyd.watch import Watch, EventMap class Pyinotifyd: - def __init__(self, watches=[], shutdown_timeout=30, logname=None): + def __init__(self, watches=[], shutdown_timeout=30, logname="daemon"): self.set_watches(watches) self.set_shutdown_timeout(shutdown_timeout) - logname = (logname or "daemon") + logname = (logname or __name__) self._log = logging.getLogger(logname) self._loop = asyncio.get_event_loop() self._notifiers = [] diff --git a/pyinotifyd/filemanager.py b/pyinotifyd/filemanager.py index 43ef988..02952c7 100755 --- a/pyinotifyd/filemanager.py +++ b/pyinotifyd/filemanager.py @@ -66,7 +66,7 @@ class Rule: class FileManager: - def __init__(self, rules, logname=None): + def __init__(self, rules, logname="filemgr"): if not isinstance(rules, list): rules = [rules] diff --git a/pyinotifyd/scheduler.py b/pyinotifyd/scheduler.py index 347116a..ca2dfa7 100755 --- a/pyinotifyd/scheduler.py +++ b/pyinotifyd/scheduler.py @@ -20,7 +20,7 @@ from uuid import uuid4 class _Task: def __init__(self, event, delay, task_id, task, callback=None, - logname=None): + logname="task"): self._event = event self._path = event.pathname self._delay = delay @@ -59,7 +59,7 @@ class _Task: class TaskScheduler: - def __init__(self, task, files, dirs, delay=0, logname=None): + def __init__(self, task, files, dirs, delay=0, logname="sched"): assert callable(task), \ f"task: expected callable, got {type(task)}" self._task = task @@ -127,13 +127,12 @@ class TaskScheduler: class ShellScheduler(TaskScheduler): - def __init__(self, cmd, task=None, logname=None, *args, **kwargs): + def __init__(self, cmd, task=None, *args, **kwargs): assert isinstance(cmd, str), \ f"cmd: expected {type('')}, got {type(cmd)}" self._cmd = cmd - logname = (logname or __name__) - super().__init__(*args, task=self.task, logname=logname, **kwargs) + super().__init__(*args, task=self.task, **kwargs) async def task(self, event, task_id): maskname = event.maskname.split("|", 1)[0]