Skip to content

Commit

Permalink
per class logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jschlyter committed Jun 17, 2024
1 parent 2fbe660 commit 3762bda
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions evrec/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@

class EvrecServer:
def __init__(self, settings: Settings):
self.logger = logging.getLogger(__name__).getChild(self.__class__.__name__)
self.settings = settings
if self.settings.mqtt_topic_write is None:
logger.warning("Not publishing verified messages")
self.logger.warning("Not publishing verified messages")
self.clients_keys = self.get_clients_keys()
self.message_validator = MessageValidator()

Expand All @@ -85,7 +86,7 @@ def get_clients_keys(self) -> JWKSet:
with open(filename, "rb") as fp:
key = JWK.from_pem(fp.read())
key.kid = filename.name.removesuffix(".pem")
logger.debug("Adding key kid=%s (%s)", key.kid, key.thumbprint())
self.logger.debug("Adding key kid=%s (%s)", key.kid, key.thumbprint())
res.add(key)
return res

Expand All @@ -97,7 +98,7 @@ async def run(self):
await client.subscribe(self.settings.mqtt_topic_read)

async for message in client.messages:
logger.debug("Received message on %s", message.topic)
self.logger.debug("Received message on %s", message.topic)
try:
jws = JWS()
jws.deserialize(message.payload)
Expand All @@ -108,13 +109,13 @@ async def run(self):
if self.settings.mqtt_topic_write:
await self.handle_payload(client, message, jws, key)
else:
logger.debug("Not publishing verified message")
self.logger.debug("Not publishing verified message")
except JWKeyNotFound:
logger.warning(
self.logger.warning(
"Dropping unverified message on %s", message.topic
)
except Exception as exc:
logger.error(
self.logger.error(
"Error parsing message on %s",
message.topic,
exc_info=exc,
Expand Down Expand Up @@ -143,7 +144,7 @@ async def handle_payload(
retain=message.retain,
properties=properties,
)
logger.info("Published verified message from %s on %s", key.kid, new_topic)
self.logger.info("Published verified message from %s on %s", key.kid, new_topic)


def verify_jws_with_keys(jws: JWS, keys: JWKSet) -> JWK:
Expand Down

0 comments on commit 3762bda

Please sign in to comment.