From 1250f23c445a733a58f1a5c4c186a6cbfd3106a3 Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Tue, 14 Feb 2023 10:48:56 +0100 Subject: [PATCH] Fix petits logging regressions from `feature/click-cli` merge (#6940) * Add back initialization events * Fix log_cache_events. Default stdout logger knows less than it used to * Add back exception handling events * Revert "Add back exception handling events" This reverts commit 26f22d91b660f51f0df6a59f9e5cae16b0ee6fe5. * Add changelog entry * Fix test by stringifying dict values * Add generated CLI API docs --------- Co-authored-by: Github Build Bot --- .../unreleased/Fixes-20230213-130522.yaml | 6 +++++ core/dbt/cli/requires.py | 17 +++++++++++--- .../docs/build/doctrees/environment.pickle | Bin 207366 -> 207366 bytes core/dbt/events/functions.py | 22 +++++++++++------- 4 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 .changes/unreleased/Fixes-20230213-130522.yaml diff --git a/.changes/unreleased/Fixes-20230213-130522.yaml b/.changes/unreleased/Fixes-20230213-130522.yaml new file mode 100644 index 00000000000..622441e72ec --- /dev/null +++ b/.changes/unreleased/Fixes-20230213-130522.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Readd initialization events, --log-cache-events in new CLI +time: 2023-02-13T13:05:22.989477+01:00 +custom: + Author: jtcohen6 + Issue: "6933" diff --git a/core/dbt/cli/requires.py b/core/dbt/cli/requires.py index b8fcec358b9..dca89d35627 100644 --- a/core/dbt/cli/requires.py +++ b/core/dbt/cli/requires.py @@ -1,13 +1,16 @@ +from dbt.version import installed as installed_version from dbt.adapters.factory import adapter_management, register_adapter -from dbt.flags import set_flags +from dbt.flags import set_flags, get_flag_dict 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 +from dbt.events.functions import setup_event_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 from dbt.profiler import profiler -from dbt.tracking import initialize_from_flags, track_run +from dbt.tracking import active_user, initialize_from_flags, track_run +from dbt.utils import cast_dict_to_dict_of_strings from click import Context from functools import update_wrapper @@ -37,6 +40,14 @@ def wrapper(*args, **kwargs): flags.DEBUG, ) + # Now that we have our logger, fire away! + fire_event(MainReportVersion(version=str(installed_version), log_version=LOG_VERSION)) + flags_dict_str = cast_dict_to_dict_of_strings(get_flag_dict()) + fire_event(MainReportArgs(args=flags_dict_str)) + + if active_user is not None: # mypy appeasement, always true + fire_event(MainTrackingUserState(user_state=active_user.state())) + # Profiling if flags.RECORD_TIMING_INFO: ctx.with_resource(profiler(enable=True, outfile=flags.RECORD_TIMING_INFO)) diff --git a/core/dbt/docs/build/doctrees/environment.pickle b/core/dbt/docs/build/doctrees/environment.pickle index f999a716d9dd676cce7d8486fd6fbdde74859b15..082c8168167fd3795d92360564ca3e893352e9af 100644 GIT binary patch delta 33 ncmZp>!qawzXG4=b+pkFxKCyAl9rEoR@{B;tw7o-~xsD3}?a2&* delta 33 ncmZp>!qawzXG4=b+s`?{E%q;)JLKCt LoggerConfig: + flags = get_flags() fmt = LineFormat.PlainText if log_format == "json": fmt = LineFormat.Json elif debug: fmt = LineFormat.DebugText level = EventLevel.DEBUG if debug else EventLevel.INFO + # We don't have access to these values when we need to setup the default stdout logger! + log_cache_events = ( + bool(flags.LOG_CACHE_EVENTS) if hasattr(flags, "LOG_CACHE_EVENTS") else False + ) + quiet = bool(flags.QUIET) if hasattr(flags, "QUIET") else False return LoggerConfig( name="stdout_log", level=level, @@ -57,9 +62,9 @@ def _get_stdout_config(log_format: str, debug: bool, use_colors: bool) -> Logger scrubber=env_scrubber, filter=partial( _stdout_filter, - bool(flags_module.LOG_CACHE_EVENTS), + log_cache_events, debug, - bool(flags_module.QUIET), + quiet, log_format, ), output_stream=sys.stdout, @@ -124,10 +129,11 @@ 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() +# Problem: This needs to be set *BEFORE* we've resolved any flags (even CLI params) EVENT_MANAGER.add_logger( - _get_logbook_log_config(flags_module.DEBUG) # type: ignore - if flags_module.ENABLE_LEGACY_LOGGER - else _get_stdout_config(flags_module.LOG_FORMAT, flags_module.DEBUG, flags_module.USE_COLORS) # type: ignore + _get_logbook_log_config(debug=False) # type: ignore + if ENABLE_LEGACY_LOGGER + else _get_stdout_config(log_format="text", debug=False, use_colors=True) # type: ignore ) # This global, and the following two functions for capturing stdout logs are