Skip to content

Commit

Permalink
refactor(logger): update get_logger to accept optional logging level …
Browse files Browse the repository at this point in the history
…and enhance docstring
  • Loading branch information
giuseppeambrosio97 committed Dec 27, 2024
1 parent 1e1cd13 commit 01e80ae
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion focoos/utils/logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import logging.config
from functools import cache
from typing import Optional

from focoos.config import FOCOOS_CONFIG, LogLevel

Expand Down Expand Up @@ -65,7 +66,23 @@ def format(self, record):


@cache
def get_logger(name="focoos", level: LogLevel = FOCOOS_CONFIG.focoos_log_level):
def get_logger(name="focoos", level: Optional[LogLevel] = None) -> logging.Logger:
"""
Get a logger instance with the specified name and logging level.
Args:
name (str, optional): The name of the logger. Defaults to "focoos".
level (LogLevel, optional): The logging level to set. If None, uses the level from FOCOOS_CONFIG (default to DEBUG).
Must be one of the standard Python logging levels (DEBUG, INFO, WARNING, ERROR, CRITICAL).
Returns:
logging.Logger: A configured logger instance with the specified name and level.
Example:
>>> logger = get_logger("my_module", logging.INFO)
>>> logger.info("This is an info message")
"""
level = level or FOCOOS_CONFIG.focoos_log_level
logger = logging.getLogger(name)
logger.setLevel(level)
return logger
Expand Down

0 comments on commit 01e80ae

Please sign in to comment.