Skip to content

Commit

Permalink
Env var shim to enable legacy logger (#4255)
Browse files Browse the repository at this point in the history
* Env var shim to reenable logbook

* Rename to ENABLE_LEGACY_LOGGER
  • Loading branch information
jtcohen6 authored Nov 9, 2021
1 parent 5e6be16 commit 6dd9c2c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
20 changes: 19 additions & 1 deletion core/dbt/events/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions core/dbt/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
3 changes: 2 additions & 1 deletion core/dbt/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 6dd9c2c

Please sign in to comment.