Coverage for hadal/custom_logger.py: 100%

1"""This module contains the `fuction default custom logger` that can be used to create a logger with a specified name, level, and format."""

2 from __future__ import annotations

3

4 import logging

5

6

7 def default_custom_logger(

8 name: str,

9 level: int | None = logging.DEBUG,

10 log_format: str | None = None,

11) -> logging.Logger:

12 """Create a logger with a specified name, level, and format.

13

14 Args:

15 name (str): The name of the logger.

16 level (int | None, optional): Logging level.

17 log_format (str | None, optional): The format of the log messages. If `None`, the default format is `%(asctime)s | %(name)s | %(module)s | %(levelname)s | %(message)s`.

18

19 Returns:

20 logger (logging.Logger): A logger object with the specified name, logging level, and format.

21 """

22 if log_format is None:

23 log_format = "%(asctime)s | %(name)s | %(module)s | %(levelname)s | %(message)s"

24

25 datefmt = "%Y-%m-%d %H:%M:%S"

26

27 logger = logging.basicConfig(level=level, format=log_format, datefmt=datefmt, encoding="utf-8")

28 logger = logging.getLogger(name=name)

29

30 return logger