Skip to content

Commit

Permalink
Handle exec info (#4168)
Browse files Browse the repository at this point in the history
handle exec info
  • Loading branch information
Nathaniel May authored and emmyoop committed Nov 8, 2021
1 parent 35dcd4d commit 0d838be
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
50 changes: 43 additions & 7 deletions core/dbt/events/functions.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()}"
Expand Down
8 changes: 8 additions & 0 deletions core/dbt/events/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from abc import ABCMeta, abstractmethod
from dataclasses import dataclass
from typing import Any


# types to represent log levels
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0d838be

Please sign in to comment.