Thread logger correctly down to sub-objects

This commit is contained in:
Luke Murphy 2021-02-02 21:34:03 +01:00
parent 0043e7563a
commit b71c2fedfc
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
1 changed files with 6 additions and 4 deletions

View File

@ -26,9 +26,10 @@ class SimpleDatabase(dict):
ease of hacking and accessibility and not for performance or efficiency.
"""
def __init__(self, filename, *args, **kwargs):
def __init__(self, filename, *args, log=None, **kwargs):
"""Initialise the object."""
self.filename = Path(filename).absolute()
self.log = log
self._loads()
self.update(*args, **kwargs)
@ -79,6 +80,7 @@ class SimpleMessage:
"""Initialise the object."""
self.message = message
self.bot = bot
self.log = self.bot.log
@property
def text(self):
@ -109,7 +111,7 @@ class SimpleMessage:
filtered = list(filter(None, split))
return filtered[-1].strip()
except Exception as exception:
self.bot.log.error(f"Couldn't parse {body}: {exception}")
self.log.error(f"Couldn't parse {body}: {exception}")
return None
@property
@ -670,7 +672,7 @@ class Bot(ClientXMPP):
if self.storage == "file":
try:
self.db = SimpleDatabase(file_storage_path)
self.db = SimpleDatabase(file_storage_path, log=self.log)
self.log.info("Successfully loaded file storage")
except Exception as exception:
message = f"Failed to load {file_storage_path}: {exception}"
@ -707,7 +709,7 @@ class Bot(ClientXMPP):
try:
internal_storage_path = f"{internal_dir}/data.json"
self._data = SimpleDatabase(internal_storage_path)
self._data = SimpleDatabase(internal_storage_path, log=self.log)
self.log.info("Successfully loaded internal storage")
except Exception as exception:
message = f"Failed to load {internal_storage_path}: {exception}"