Skip to content

Commit

Permalink
CT-1917: Fix a regression in the behavior of the -q/--quiet cli param…
Browse files Browse the repository at this point in the history
…eter (#6886)
  • Loading branch information
peterallenwebb authored Feb 7, 2023
1 parent 4c63b63 commit ccb4fa2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230207-143544.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Fix regression of --quiet cli parameter behavior
time: 2023-02-07T14:35:44.160163-05:00
custom:
Author: peterallenwebb
Issue: "6749"
12 changes: 9 additions & 3 deletions core/dbt/events/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
metadata_vars: Optional[Dict[str, str]] = None


# The "fallback" logger is used as a stop-gap so that console logging works before the logging
# configuration is fully loaded.
def setup_fallback_logger(use_legacy: bool, level: EventLevel) -> None:
cleanup_event_logger()
config = _get_logbook_log_config(level) if use_legacy else _get_stdout_config(level)
EVENT_MANAGER.add_logger(config)


def setup_event_logger(log_path: str, level_override: Optional[EventLevel] = None):
cleanup_event_logger()
make_log_dir_if_missing(log_path)
Expand Down Expand Up @@ -113,9 +121,7 @@ def cleanup_event_logger():
# currently fire before logs can be configured by setup_event_logger(), we
# create a default configuration with default settings and no file output.
EVENT_MANAGER: EventManager = EventManager()
EVENT_MANAGER.add_logger(
_get_logbook_log_config() if flags.ENABLE_LEGACY_LOGGER else _get_stdout_config()
)
setup_fallback_logger(bool(flags.ENABLE_LEGACY_LOGGER), EventLevel.INFO)


# This global, and the following two functions for capturing stdout logs are
Expand Down
10 changes: 9 additions & 1 deletion core/dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
from pathlib import Path

import dbt.version
from dbt.events.functions import fire_event, setup_event_logger, LOG_VERSION
from dbt.events.functions import fire_event, setup_event_logger, setup_fallback_logger, LOG_VERSION
from dbt.events.types import (
EventLevel,
MainEncounteredError,
MainKeyboardInterrupt,
MainReportVersion,
Expand Down Expand Up @@ -178,6 +179,13 @@ def handle_and_check(args):
# Set flags from args, user config, and env vars
user_config = read_user_config(flags.PROFILES_DIR) # This is read again later
flags.set_from_args(parsed, user_config)

# If the user has asked to supress non-error logging on the cli, we want to respect that as soon as possible,
# so that any non-error logging done before full log config is loaded and ready is filtered accordingly.
setup_fallback_logger(
bool(flags.ENABLE_LEGACY_LOGGER), EventLevel.ERROR if flags.QUIET else EventLevel.INFO
)

dbt.tracking.initialize_from_flags()
# Set log_format from flags
parsed.cls.set_log_format()
Expand Down

0 comments on commit ccb4fa2

Please sign in to comment.