-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathlogs.py
More file actions
49 lines (33 loc) · 1.54 KB
/
logs.py
File metadata and controls
49 lines (33 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Application logging using loguru with category-based control."""
from __future__ import annotations
from typing import TYPE_CHECKING
from loguru import logger
from app.config.log_config import LogCategory, log_config
if TYPE_CHECKING:
from loguru import Logger
class CategoryLogger:
"""Logger wrapper that checks categories before logging.
This eliminates the need for if-statements in calling code, reducing
cyclomatic complexity.
"""
def __init__(self, logger: Logger) -> None:
"""Initialize with a loguru logger instance."""
self._logger = logger
def info(self, message: str, category: LogCategory) -> None:
"""Log an info message if the category is enabled."""
if log_config.is_enabled(category):
self._logger.info(message)
def error(self, message: str, category: LogCategory) -> None:
"""Log an error message if the category is enabled."""
if log_config.is_enabled(category):
self._logger.error(message)
def warning(self, message: str, category: LogCategory) -> None:
"""Log a warning message if the category is enabled."""
if log_config.is_enabled(category):
self._logger.warning(message)
def debug(self, message: str, category: LogCategory) -> None:
"""Log a debug message if the category is enabled."""
if log_config.is_enabled(category):
self._logger.debug(message)
category_logger = CategoryLogger(logger)
__all__ = ["LogCategory", "category_logger", "log_config", "logger"]