Renamed __init__ to watcher and cleaned up some logging code

Using __init__ as the home of Watcher was causing unexpected behaviour for no
good reason, so Watcher now lives in its own file as normal.

There was logging configuration pertaining to processes which is not
meaningful here, so removed it. Also made sure there are no
unexpected log handlers.
This commit is contained in:
Erik Thuning 2024-06-13 14:40:33 +02:00
parent c910635a41
commit cf5d0537ac
2 changed files with 8 additions and 7 deletions

@ -1,11 +1,12 @@
import logging
import logging.handlers
import signal
import sys
from configparser import ConfigParser
from pathlib import Path
import watcher
from .watcher import Watcher
conffile = Path('config.ini')
@ -21,13 +22,12 @@ if 'logging' not in config:
# Basic logging settings
baselogger = logging.getLogger('arec-watcher')
if baselogger.hasHandlers():
baselogger.handlers = []
log_level = config['logging'].get('level', 'ERROR')
baselogger.setLevel(log_level)
fmt = logging.Formatter('%(levelname)s in %(name)s: %(message)s')
if baselogger.getEffectiveLevel() <= logging.DEBUG:
fmt = logging.Formatter(
'%(levelname)s in %(name)s (%(process)d): %(message)s')
stderrlog = logging.StreamHandler()
stderrlog.setLevel(log_level)
@ -48,8 +48,8 @@ if 'mail_level' in config['logging']:
baselogger.addHandler(maillog)
watch = watcher.Watcher(Path(config['arec-watcher']['watchdir']),
config['arec-watcher']['notify_url'])
watch = Watcher(Path(config['arec-watcher']['watchdir']),
config['arec-watcher']['notify_url'])
watch.start()
try:

@ -64,7 +64,8 @@ class Watcher(PatternMatchingEventHandler):
except requests.HTTPError as e:
self.logger.error('Failed to notify %s about %s',
self.notify_url,
basedir)
basedir,
exc_info=e)
def on_created(self, event):
self._process(Path(event.src_path))