MCPcopy
hub / github.com/cookiecutter/cookiecutter / configure_logger

Function configure_logger

cookiecutter/log.py:22–56  ·  view source on GitHub ↗

Configure logging for cookiecutter. Set up logging to stdout with given level. If ``debug_file`` is given set up logging to file with DEBUG level.

(
    stream_level: str = 'DEBUG', debug_file: str | None = None
)

Source from the content-addressed store, hash-verified

20
21
22def configure_logger(
23 stream_level: str = 'DEBUG', debug_file: str | None = None
24) -> logging.Logger:
25 """Configure logging for cookiecutter.
26
27 Set up logging to stdout with given level. If ``debug_file`` is given set
28 up logging to file with DEBUG level.
29 """
30 # Set up 'cookiecutter' logger
31 logger = logging.getLogger('cookiecutter')
32 logger.setLevel(logging.DEBUG)
33
34 # Remove all attached handlers, in case there was
35 # a logger with using the name 'cookiecutter'
36 del logger.handlers[:]
37
38 # Create a file handler if a log file is provided
39 if debug_file is not None:
40 debug_formatter = logging.Formatter(LOG_FORMATS['DEBUG'])
41 file_handler = logging.FileHandler(debug_file)
42 file_handler.setLevel(LOG_LEVELS['DEBUG'])
43 file_handler.setFormatter(debug_formatter)
44 logger.addHandler(file_handler)
45
46 # Get settings based on the given stream_level
47 log_formatter = logging.Formatter(LOG_FORMATS[stream_level])
48 log_level = LOG_LEVELS[stream_level]
49
50 # Create a stream handler
51 stream_handler = logging.StreamHandler(stream=sys.stdout)
52 stream_handler.setLevel(log_level)
53 stream_handler.setFormatter(log_formatter)
54 logger.addHandler(stream_handler)
55
56 return logger

Callers 4

mainFunction · 0.90
info_loggerFunction · 0.90
debug_loggerFunction · 0.90
info_logger_with_fileFunction · 0.90

Calls

no outgoing calls

Tested by 3

info_loggerFunction · 0.72
debug_loggerFunction · 0.72
info_logger_with_fileFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…