Coverage for databooks/logging.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-10-03 12:27 +0000

1"""Logging helper functions.""" 

2 

3import logging 

4import os 

5 

6from rich.logging import RichHandler 

7 

8 

9def get_logger(name: str) -> logging.Logger: 

10 """Get logger with rich configuration.""" 

11 level = os.getenv("LOG_LEVEL", logging.INFO) 

12 logging.basicConfig( 

13 level=level, 

14 format="%(message)s", 

15 datefmt="[%X]", 

16 handlers=[RichHandler(rich_tracebacks=True)], 

17 ) 

18 return logging.getLogger(name) 

19 

20 

21def set_verbose(logger: logging.Logger) -> None: 

22 """Set logger to DEBUG level when user requests verbosity.""" 

23 verbose_level = logging.DEBUG 

24 if logger.level < verbose_level: 

25 logger.setLevel(logging.DEBUG) 

26 logger.debug( 

27 f"Verbose mode: setting log level to {logging.getLevelName(verbose_level)}" 

28 )