diff --git a/matrix_webhook/app.py b/matrix_webhook/app.py index fb202ad..6f40386 100644 --- a/matrix_webhook/app.py +++ b/matrix_webhook/app.py @@ -18,16 +18,19 @@ async def main(event): matrix client login & start web server """ if conf.MATRIX_PW: - LOGGER.info(f"Log in {conf.MATRIX_ID=} on {conf.MATRIX_URL=}") + msg = f"Log in {conf.MATRIX_ID=} on {conf.MATRIX_URL=}" + LOGGER.info(msg) await utils.CLIENT.login(conf.MATRIX_PW) else: - LOGGER.info(f"Restoring log in {conf.MATRIX_ID=} on {conf.MATRIX_URL=}") + msg = f"Restoring log in {conf.MATRIX_ID=} on {conf.MATRIX_URL=}" + LOGGER.info(msg) utils.CLIENT.access_token = conf.MATRIX_TOKEN server = web.Server(handler.matrix_webhook) runner = web.ServerRunner(server) await runner.setup() - LOGGER.info(f"Binding on {conf.SERVER_ADDRESS=}") + msg = f"Binding on {conf.SERVER_ADDRESS=}" + LOGGER.info(msg) if conf.SERVER_PATH: site = web.UnixSite(runner, conf.SERVER_PATH) else: diff --git a/matrix_webhook/handler.py b/matrix_webhook/handler.py index 5efbf1e..ed40449 100644 --- a/matrix_webhook/handler.py +++ b/matrix_webhook/handler.py @@ -17,7 +17,8 @@ async def matrix_webhook(request): This one handles a POST, checks its content, and forwards it to the matrix room. """ - LOGGER.debug(f"Handling {request=}") + msg = f"Handling {request=}" + LOGGER.debug(msg) # healthcheck if request.rel_url.path == "/health": diff --git a/matrix_webhook/utils.py b/matrix_webhook/utils.py index 4fa379f..724f706 100644 --- a/matrix_webhook/utils.py +++ b/matrix_webhook/utils.py @@ -33,14 +33,16 @@ def error_map(resp): def create_json_response(status, ret): """Create a JSON response.""" - LOGGER.debug(f"Creating json response: {status=}, {ret=}") + msg = f"Creating json response: {status=}, {ret=}" + LOGGER.debug(msg) response_data = {"status": status, "ret": ret} return web.json_response(response_data, status=status) async def join_room(room_id): """Try to join the room.""" - LOGGER.debug(f"Join room {room_id=}") + msg = f"Join room {room_id=}" + LOGGER.debug(msg) for _ in range(10): try: @@ -55,14 +57,16 @@ async def join_room(room_id): else: return None except LocalProtocolError as e: - LOGGER.error(f"Send error: {e}") + msg = f"Send error: {e}" + LOGGER.error(msg) LOGGER.warning("Trying again") return create_json_response(HTTPStatus.GATEWAY_TIMEOUT, "Homeserver not responding") async def send_room_message(room_id, content): """Send a message to a room.""" - LOGGER.debug(f"Sending room message in {room_id=}: {content=}") + msg = f"Sending room message in {room_id=}: {content=}" + LOGGER.debug(msg) for _ in range(10): try: @@ -81,6 +85,7 @@ async def send_room_message(room_id, content): else: return create_json_response(HTTPStatus.OK, "OK") except LocalProtocolError as e: - LOGGER.error(f"Send error: {e}") + msg = f"Send error: {e}" + LOGGER.error(msg) LOGGER.warning("Trying again") return create_json_response(HTTPStatus.GATEWAY_TIMEOUT, "Homeserver not responding")