Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CT-2022: Fix --quiet and DBT_ENABLE_LEGACY_LOGGER during initialization #7048

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230224-162828.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Fix --quiet and DBT_ENABLE_LEGACY_LOGGER to work during initialization
time: 2023-02-24T16:28:28.195993-05:00
custom:
Author: peterallenwebb
Issue: "6847"
12 changes: 10 additions & 2 deletions core/dbt/cli/requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from dbt.cli.flags import Flags
from dbt.config import RuntimeConfig
from dbt.config.runtime import load_project, load_profile, UnsetProfile
from dbt.events.functions import setup_event_logger, fire_event, LOG_VERSION
from dbt.events.base_types import EventLevel
from dbt.events.functions import setup_event_logger, setup_fallback_logger, fire_event, LOG_VERSION
from dbt.events.types import MainReportVersion, MainReportArgs, MainTrackingUserState
from dbt.exceptions import DbtProjectError
from dbt.parser.manifest import ManifestLoader, write_manifest
Expand All @@ -22,6 +23,14 @@ def wrapper(*args, **kwargs):
assert isinstance(ctx, Context)
ctx.obj = ctx.obj or {}

# Since loggable events can happen while the flags and user config are being read, look for
# and enforce certain logging command line parameters early to ensure they take effect.
parent_params = ctx.parent.params
setup_fallback_logger(
bool(parent_params["enable_legacy_logger"]),
EventLevel.ERROR if parent_params["quiet"] else EventLevel.INFO,
)

# Flags
flags = Flags(ctx)
ctx.obj["flags"] = flags
Expand All @@ -32,7 +41,6 @@ def wrapper(*args, **kwargs):
ctx.with_resource(track_run(run_command=flags.WHICH))

# Logging
# N.B. Legacy logger is not supported
setup_event_logger(flags)

# Now that we have our logger, fire away!
Expand Down
Binary file modified core/dbt/docs/build/doctrees/environment.pickle
Binary file not shown.
15 changes: 10 additions & 5 deletions core/dbt/events/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
metadata_vars: Optional[Dict[str, str]] = None


def setup_fallback_logger(enable_legacy_logger: bool, level: EventLevel):
cleanup_event_logger()
EVENT_MANAGER.add_logger(
_get_logbook_log_config(False, True, False, False) # type: ignore
if enable_legacy_logger
else _get_stdout_config(LineFormat.PlainText, False, True, level, False, False)
)


def setup_event_logger(flags) -> None:
cleanup_event_logger()
make_log_dir_if_missing(flags.LOG_PATH)
Expand Down Expand Up @@ -169,11 +178,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(False, True, False, False) # type: ignore
if ENABLE_LEGACY_LOGGER
else _get_stdout_config(LineFormat.PlainText, False, True, EventLevel.INFO, False, False)
)
setup_fallback_logger(bool(ENABLE_LEGACY_LOGGER), EventLevel.INFO)

# This global, and the following two functions for capturing stdout logs are
# an unpleasant hack we intend to remove as part of API-ification. The GitHub
Expand Down