Skip to content

Commit

Permalink
Make logging binary : warning or debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Nov 25, 2022
1 parent a2bbdb0 commit d5cd537
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
26 changes: 9 additions & 17 deletions qgis_deployment_toolbelt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
# chronometer
START_TIME = default_timer()

# logs
logger = logging.getLogger(__name__)
log_console_handler = logging.StreamHandler()
logger.addHandler(log_console_handler)

# default CLI context.
# See: https://click.palletsprojects.com/en/7.x/commands/#context-defaults
CONTEXT_SETTINGS = dict(obj={})
Expand Down Expand Up @@ -135,9 +130,15 @@ def qgis_deployment_toolbelt(
# -- LOG/VERBOSITY MANAGEMENT ------------------------------------------------------
# if verbose, override conf value
if verbose:
logger.setLevel(logging.DEBUG)
for h in logger.handlers:
h.setLevel(logging.DEBUG)
log_level = logging.DEBUG
else:
log_level = logging.WARNING

logging.basicConfig(
format="[%(levelname)s] %(message)s",
level=log_level,
)
logger = logging.getLogger(__name__)
logger.info(f"{logging.getLevelName(logger.getEffectiveLevel())} mode enabled.")

click.echo(
Expand All @@ -156,15 +157,6 @@ def qgis_deployment_toolbelt(
if result_scenario_validity is not None:
exit_cli_error(result_scenario_validity)

# Apply log level from scenario (only if verbose mode is disabled)
if scenario.settings.get("DEBUG") is True and not verbose:
logger.setLevel(logging.DEBUG)
for h in logger.handlers:
h.setLevel(logging.DEBUG)
logger.info(
f"{logging.getLevelName(logger.getEffectiveLevel())} mode enabled."
)

# Use metadata to inform which scenario is running
click.echo(
"Running scenario: {title} ({id}).\n{description}".format(
Expand Down
1 change: 0 additions & 1 deletion scenario.qdt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ metadata:
# Toolbelt settings
settings:
DEBUG: true
SCENARIO_VALIDATION: true

# Deployment workflow, step by step
Expand Down

0 comments on commit d5cd537

Please sign in to comment.