diff --git a/core/dbt/events/functions.py b/core/dbt/events/functions.py index 5d83c5cf735..a1ef7bf6244 100644 --- a/core/dbt/events/functions.py +++ b/core/dbt/events/functions.py @@ -4,7 +4,7 @@ from dbt.events.types import Cli, Event, File, ShowException import dbt.flags as flags # TODO this will need to move eventually -from dbt.logger import SECRET_ENV_PREFIX, make_log_dir_if_missing +from dbt.logger import SECRET_ENV_PREFIX, make_log_dir_if_missing, GLOBAL_LOGGER import io from io import StringIO import json @@ -206,6 +206,24 @@ def fire_event(e: Event) -> None: # explicitly checking the debug flag here so that potentially expensive-to-construct # log messages are not constructed if debug messages are never shown. + # backwards compatibility for plugins that require old logger (dbt-rpc) + if flags.ENABLE_LEGACY_LOGGER: + log_line = create_log_line(e, json_fmt=this.format_json, cli_dest=False) + level_tag = e.level_tag() + if level_tag == 'debug': + GLOBAL_LOGGER.debug(log_line) + elif level_tag == 'info': + GLOBAL_LOGGER.info(log_line) + elif level_tag == 'warn': + GLOBAL_LOGGER.warn(log_line) + elif level_tag == 'error': + GLOBAL_LOGGER.error(log_line) + else: + raise AssertionError( + f"While attempting to log {log_line}, encountered the unhandled level: {level_tag}" + ) + return + # always logs debug level regardless of user input if isinstance(e, File): log_line = create_log_line(e, json_fmt=this.format_json, cli_dest=False) diff --git a/core/dbt/flags.py b/core/dbt/flags.py index a05c7d0ecd8..ce46d0a15f4 100644 --- a/core/dbt/flags.py +++ b/core/dbt/flags.py @@ -81,6 +81,7 @@ def env_set_path(key: str) -> Optional[Path]: MACRO_DEBUGGING = env_set_truthy('DBT_MACRO_DEBUGGING') DEFER_MODE = env_set_truthy('DBT_DEFER_TO_STATE') ARTIFACT_STATE_PATH = env_set_path('DBT_ARTIFACT_STATE_PATH') +ENABLE_LEGACY_LOGGER = env_set_truthy('DBT_ENABLE_LEGACY_LOGGER') def _get_context(): diff --git a/core/dbt/logger.py b/core/dbt/logger.py index c11b6c8e6b3..9d8adbe5551 100644 --- a/core/dbt/logger.py +++ b/core/dbt/logger.py @@ -576,7 +576,8 @@ def log_cache_events(flag): CACHE_LOGGER.disabled = not flag -logger.disable() +if not dbt.flags.ENABLE_LEGACY_LOGGER: + logger.disable() GLOBAL_LOGGER = logger