From 0d838bebac771986164e6ef2f7a0ec0d9c9ca063 Mon Sep 17 00:00:00 2001 From: Nathaniel May Date: Fri, 29 Oct 2021 16:01:04 -0400 Subject: [PATCH] Handle exec info (#4168) handle exec info --- core/dbt/events/functions.py | 50 +++++++++++++++++++++++++++++++----- core/dbt/events/types.py | 8 ++++++ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/core/dbt/events/functions.py b/core/dbt/events/functions.py index fea072ff8b2..5c97ed7fb32 100644 --- a/core/dbt/events/functions.py +++ b/core/dbt/events/functions.py @@ -1,7 +1,7 @@ import dbt.logger as logger # type: ignore # TODO eventually remove dependency on this logger from dbt.events.history import EVENT_HISTORY -from dbt.events.types import CliEventABC, Event +from dbt.events.types import CliEventABC, Event, ShowException # top-level method for accessing the new eventing system @@ -11,17 +11,53 @@ def fire_event(e: Event) -> None: EVENT_HISTORY.append(e) if isinstance(e, CliEventABC): - if e.level_tag() == 'test': + if e.level_tag() == 'test' and not isinstance(e, ShowException): # TODO after implmenting #3977 send to new test level logger.GLOBAL_LOGGER.debug(logger.timestamped_line(e.cli_msg())) - elif e.level_tag() == 'debug': + elif e.level_tag() == 'test' and isinstance(e, ShowException): + # TODO after implmenting #3977 send to new test level + logger.GLOBAL_LOGGER.debug( + logger.timestamped_line(e.cli_msg()), + exc_info=e.exc_info, + stack_info=e.stack_info, + extra=e.extra + ) + elif e.level_tag() == 'debug' and not isinstance(e, ShowException): logger.GLOBAL_LOGGER.debug(logger.timestamped_line(e.cli_msg())) - elif e.level_tag() == 'info': + elif e.level_tag() == 'debug' and isinstance(e, ShowException): + logger.GLOBAL_LOGGER.debug( + logger.timestamped_line(e.cli_msg()), + exc_info=e.exc_info, + stack_info=e.stack_info, + extra=e.extra + ) + elif e.level_tag() == 'info' and not isinstance(e, ShowException): logger.GLOBAL_LOGGER.info(logger.timestamped_line(e.cli_msg())) - elif e.level_tag() == 'warn': - logger.GLOBAL_LOGGER.warning()(logger.timestamped_line(e.cli_msg())) - elif e.level_tag() == 'error': + elif e.level_tag() == 'info' and isinstance(e, ShowException): + logger.GLOBAL_LOGGER.info( + logger.timestamped_line(e.cli_msg()), + exc_info=e.exc_info, + stack_info=e.stack_info, + extra=e.extra + ) + elif e.level_tag() == 'warn' and not isinstance(e, ShowException): + logger.GLOBAL_LOGGER.warning(logger.timestamped_line(e.cli_msg())) + elif e.level_tag() == 'warn' and isinstance(e, ShowException): + logger.GLOBAL_LOGGER.warning( + logger.timestamped_line(e.cli_msg()), + exc_info=e.exc_info, + stack_info=e.stack_info, + extra=e.extra + ) + elif e.level_tag() == 'error' and not isinstance(e, ShowException): logger.GLOBAL_LOGGER.error(logger.timestamped_line(e.cli_msg())) + elif e.level_tag() == 'error' and isinstance(e, ShowException): + logger.GLOBAL_LOGGER.error( + logger.timestamped_line(e.cli_msg()), + exc_info=e.exc_info, + stack_info=e.stack_info, + extra=e.extra + ) else: raise AssertionError( f"Event type {type(e).__name__} has unhandled level: {e.level_tag()}" diff --git a/core/dbt/events/types.py b/core/dbt/events/types.py index 892061417ad..c8a1c8dedc1 100644 --- a/core/dbt/events/types.py +++ b/core/dbt/events/types.py @@ -1,5 +1,6 @@ from abc import ABCMeta, abstractmethod from dataclasses import dataclass +from typing import Any # types to represent log levels @@ -30,6 +31,13 @@ def level_tag(self) -> str: return "error" +@dataclass +class ShowException(): + exc_info: Any = None + stack_info: Any = None + extra: Any = None + + # The following classes represent the data necessary to describe a # particular event to both human readable logs, and machine reliable # event streams. classes extend superclasses that indicate what