diff --git a/.changes/unreleased/Fixes-20221214-155307.yaml b/.changes/unreleased/Fixes-20221214-155307.yaml new file mode 100644 index 00000000000..cb37e0a809c --- /dev/null +++ b/.changes/unreleased/Fixes-20221214-155307.yaml @@ -0,0 +1,7 @@ +kind: Fixes +body: Repair a regression which prevented basic logging before the logging subsystem + is completely configured. +time: 2022-12-14T15:53:07.396512-05:00 +custom: + Author: peterallenwebb + Issue: "6434" diff --git a/core/dbt/events/functions.py b/core/dbt/events/functions.py index bfdf9cf2714..36dd2e9ba79 100644 --- a/core/dbt/events/functions.py +++ b/core/dbt/events/functions.py @@ -38,7 +38,7 @@ def setup_event_logger(log_path: str, level_override: Optional[EventLevel] = Non EVENT_MANAGER.add_logger(_get_logfile_config(os.path.join(log_path, "dbt.log"))) -def _get_stdout_config(level: Optional[EventLevel]) -> LoggerConfig: +def _get_stdout_config(level: Optional[EventLevel] = None) -> LoggerConfig: fmt = LineFormat.PlainText if flags.LOG_FORMAT == "json": fmt = LineFormat.Json @@ -90,7 +90,7 @@ def _logfile_filter(log_cache_events: bool, evt: BaseEvent) -> bool: ) -def _get_logbook_log_config(level: Optional[EventLevel]) -> LoggerConfig: +def _get_logbook_log_config(level: Optional[EventLevel] = None) -> LoggerConfig: config = _get_stdout_config(level) config.name = "logbook_log" config.filter = NoFilter if flags.LOG_CACHE_EVENTS else lambda e: not isinstance(e, Cache) @@ -110,15 +110,14 @@ def cleanup_event_logger(): EVENT_MANAGER.callbacks.clear() -# The default event manager will not log anything, but some tests run code that -# generates events, without configuring the event manager, so we create an empty -# manager here until there is a better testing strategy in place. +# Since dbt-rpc does not do its own log setup, and since some events can +# 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() +) -# Since dbt-rpc does not do its own log setup, we set up logbook if legacy -# logging is enabled. -if flags.ENABLE_LEGACY_LOGGER: - EVENT_MANAGER.add_logger(_get_logbook_log_config(None)) # 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