Skip to content

Commit

Permalink
Enable debug cookiecutter logging for deep debug
Browse files Browse the repository at this point in the history
  • Loading branch information
rmartin16 committed Sep 29, 2023
1 parent f86386f commit 1246230
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/briefcase/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pathlib import Path

from cookiecutter import exceptions as cookiecutter_exceptions
from cookiecutter.log import configure_logger as configure_cookiecutter_logger
from cookiecutter.repository import is_repo_url
from platformdirs import PlatformDirs

Expand Down Expand Up @@ -911,6 +912,8 @@ def generate_template(self, template, branch, output_path, extra_context):
template=template, branch=branch
)

configure_cookiecutter_logger("DEBUG" if self.logger.is_deep_debug else "INFO")

try:
# Unroll the template
self.tools.cookiecutter(
Expand Down
37 changes: 37 additions & 0 deletions tests/commands/base/test_cookiecutter_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import logging

import pytest

cookiecutter_logger = logging.getLogger("cookiecutter")


@pytest.fixture
def base_command(base_command):
# Mock actual templating commands as no-ops
base_command.update_cookiecutter_cache = lambda *a, **kw: None
base_command.tools.cookiecutter = lambda *a, **kw: None
return base_command


@pytest.mark.parametrize(
"verbosity, log_level",
[
(0, logging.INFO),
(1, logging.INFO),
(2, logging.DEBUG),
],
)
def test_cookiecutter_logging_config(base_command, verbosity, log_level):
"""The loggers for cookiecutter are configured as expected."""
base_command.logger.verbosity = verbosity

base_command.generate_template(
template="", branch="", output_path="", extra_context={}
)
# call multiple times to ensure only 1 handler ever exists
base_command.generate_template(
template="", branch="", output_path="", extra_context={}
)

assert len(cookiecutter_logger.handlers) == 1
assert cookiecutter_logger.handlers[0].level == log_level

0 comments on commit 1246230

Please sign in to comment.