use logging module in subject class

patch bump
This commit is contained in:
onyx-and-iris 2022-09-29 11:31:19 +01:00
parent af0d51eeb1
commit 9c8fe0b626
2 changed files with 14 additions and 3 deletions

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "voicemeeter-api" name = "voicemeeter-api"
version = "0.8.0" version = "0.8.1"
description = "A Python wrapper for the Voiceemeter API" description = "A Python wrapper for the Voiceemeter API"
authors = ["onyx-and-iris <code@onyxandiris.online>"] authors = ["onyx-and-iris <code@onyxandiris.online>"]
license = "MIT" license = "MIT"

View File

@ -1,6 +1,11 @@
import logging
class Subject: class Subject:
"""Adds support for observers""" """Adds support for observers"""
logger = logging.getLogger("subject.subject")
def __init__(self): def __init__(self):
"""list of current observers""" """list of current observers"""
@ -22,16 +27,22 @@ class Subject:
if observer not in self._observers: if observer not in self._observers:
self._observers.append(observer) self._observers.append(observer)
self.logger.info(f"{type(observer).__name__} added to event observers")
else: else:
print(f"Failed to add: {observer}") self.logger.error(
f"Failed to add {type(observer).__name__} to event observers"
)
def remove(self, observer): def remove(self, observer):
"""removes an observer from _observers""" """removes an observer from _observers"""
try: try:
self._observers.remove(observer) self._observers.remove(observer)
self.logger.info(f"{type(observer).__name__} removed from event observers")
except ValueError: except ValueError:
print(f"Failed to remove: {observer}") self.logger.error(
f"Failed to remove {type(observer).__name__} from event observers"
)
def clear(self): def clear(self):
"""clears the _observers list""" """clears the _observers list"""