refactor(log): refactor the whole project

format: {time:YYYY-MM-DD HH:mm:ss} [{level}] | {name} | {message}
{name} is:
- Uvicorn: log from uvicorn server (#228B22)
- Service: log from class of `app.service` (blue)
- Fetcher: log from fetchers (magenta)
- Task: log from `app.tasks` (#FFD700)
- System: log from `system_logger` (red)
- Normal: log from `log(name)` (#FFC1C1)
- Default: the module name of caller

if you are writing services or tasks, you can just call `logger.`, we will pack it with name `Service` or `Task`
if you want to print fetcher logs, system-related logs, or normal logs, use `logger = (fetcher_logger / system_logger / log)(name)`
This commit is contained in:
MingxuanGame
2025-10-03 11:44:47 +00:00
parent fce88272b5
commit d23f32f08d
27 changed files with 210 additions and 174 deletions

View File

@@ -2,7 +2,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING
from app.log import logger
from app.log import log
from app.models.notification import NotificationDetails
from .base import RedisSubscriber
@@ -17,6 +17,8 @@ JOIN_CHANNEL = "chat:room:joined"
EXIT_CHANNEL = "chat:room:left"
ON_NOTIFICATION = "chat:notification"
logger = log("Chat")
class ChatSubscriber(RedisSubscriber):
def __init__(self):
@@ -49,7 +51,7 @@ class ChatSubscriber(RedisSubscriber):
try:
detail = TypeAdapter(NotificationDetails).validate_json(s)
except ValueError:
logger.exception("")
logger.exception("Failed to parse notification detail")
return
except Exception:
logger.exception("Failed to parse notification detail")