Coverage for testrail_api_reporter/utils/logger_config.py: 100%

1# -*- coding: utf-8 -*-

2"""Logger configuration"""

3

4 import logging

5 import sys

6

7 DEFAULT_LOGGING_LEVEL = logging.DEBUG

8

9

10 def setup_logger(name: str, log_file: str, level=logging.DEBUG):

11 """

12 Method to setup logger

13

14 :param name: (string) Name of the logger.

15 :param log_file: path to log_file

16 :param level: logging level. Default is logging.DEBUG

17 :returns: logger object

18 """

19 formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(name)s: %(message)s")

20

21 file_handler = logging.FileHandler(log_file)

22 file_handler.setFormatter(formatter)

23 stream_handler = logging.StreamHandler(sys.stdout)

24 stream_handler.setFormatter(formatter)

25

26 logger = logging.getLogger(name)

27 logger.setLevel(level)

28

29 logger.addHandler(file_handler)

30 logger.addHandler(stream_handler)

31

32 return logger