commit 616cd82fc3d46d8dcce19b47bd97ecb6c62fa88d
parent 544cf3fe24934d115c534029666d191a46dd721a
Author: Carlosokumu <carlosokumu254@gmail.com>
Date: Fri, 15 Aug 2025 16:37:42 +0300
add logging
Diffstat:
1 file changed, 39 insertions(+), 0 deletions(-)
diff --git a/calendarapp/logging/logging_manager.py b/calendarapp/logging/logging_manager.py
@@ -0,0 +1,38 @@
+import logging
+from typing import Optional
+
+class LoggingManager:
+ def __init__(
+ self,
+ *,
+ verbose: bool = False,
+ quiet: bool = False,
+ log_file: Optional[str] = None
+ ):
+ self._configure_logging(verbose, quiet, log_file)
+
+ def _configure_logging(
+ self,
+ verbose: bool,
+ quiet: bool,
+ log_file: Optional[str]
+ ) -> None:
+ level = logging.DEBUG if verbose else (
+ logging.CRITICAL if quiet else logging.INFO
+ )
+
+ config = {
+ "level": level,
+ "format": "%(message)s" if not verbose else "%(levelname)s: %(message)s",
+ "handlers": []
+ }
+
+ if log_file:
+ config["handlers"].append(logging.FileHandler(log_file))
+
+ logging.basicConfig(**config)
+
+ @staticmethod
+ def get_logger(name: str) -> logging.Logger:
+ """Shortcut to get a named logger."""
+ return logging.getLogger(name)
+\ No newline at end of file