From 8b23ece19421417fa1f5a4aaca6c914bdf62923c Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 23 Jan 2024 17:52:12 +0300 Subject: [PATCH] less-logs --- services/auth.py | 4 ++++ services/rediscache.py | 12 ++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/services/auth.py b/services/auth.py index 9190c4b..6912382 100644 --- a/services/auth.py +++ b/services/auth.py @@ -5,6 +5,10 @@ from settings import AUTH_URL from services.db import local_session from orm.author import Author +import logging + +logger = logging.getLogger("\t[services.auth]\t") +logger.setLevel(logging.DEBUG) async def check_auth(req) -> str | None: token = req.headers.get("Authorization") diff --git a/services/rediscache.py b/services/rediscache.py index cb2a869..3609a99 100644 --- a/services/rediscache.py +++ b/services/rediscache.py @@ -4,6 +4,10 @@ import redis.asyncio as aredis import asyncio from settings import REDIS_URL +import logging + +logger = logging.getLogger("\t[services.redis]\t") +logger.setLevel(logging.DEBUG) class RedisCache: def __init__(self, uri=REDIS_URL): @@ -21,11 +25,11 @@ class RedisCache: async def execute(self, command, *args, **kwargs): if self._client: try: - print("[redis] " + command + " " + " ".join(args)) + logger.debug(command + " " + " ".join(args)) r = await self._client.execute_command(command, *args, **kwargs) return r except Exception as e: - print(f"[redis] error: {e}") + logger.error(f"{e}") return None async def subscribe(self, *channels): @@ -56,11 +60,11 @@ class RedisCache: while True: message = await pubsub.get_message() if message and isinstance(message["data"], (str, bytes, bytearray)): - print(f"[services.rediscache] msg: {message}") + logger.debug("pubsub got msg") try: yield json.loads(message["data"]), message.get("channel") except Exception as e: - print(f"[servoces.rediscache] Error: {e}") + logger.error(f"{e}") await asyncio.sleep(1)