Skip to content

Commit

Permalink
context call sites (#4164)
Browse files Browse the repository at this point in the history
* updated context dir to new structured logging
  • Loading branch information
emmyoop committed Nov 8, 2021
1 parent 19124db commit 35dcd4d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
7 changes: 4 additions & 3 deletions core/dbt/context/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
)
from dbt.contracts.graph.compiled import CompiledResource
from dbt.exceptions import raise_compiler_error, MacroReturn, raise_parsing_error
from dbt.logger import GLOBAL_LOGGER as logger
from dbt.events.functions import fire_event
from dbt.events.types import MacroEventInfo, MacroEventDebug
from dbt.version import __version__ as dbt_version

# These modules are added to the context. Consider alternative
Expand Down Expand Up @@ -481,9 +482,9 @@ def log(msg: str, info: bool = False) -> str:
{% endmacro %}"
"""
if info:
logger.info(msg)
fire_event(MacroEventInfo(msg))
else:
logger.debug(msg)
fire_event(MacroEventDebug(msg))
return ''

@contextproperty
Expand Down
1 change: 0 additions & 1 deletion core/dbt/context/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
raise_parsing_error,
)
from dbt.config import IsFQNResource
from dbt.logger import GLOBAL_LOGGER as logger, SECRET_ENV_PREFIX # noqa
from dbt.node_types import NodeType

from dbt.utils import (
Expand Down
18 changes: 18 additions & 0 deletions core/dbt/events/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ def cli_msg(self) -> str:
return f"Performance info: {self.path}"


@dataclass
class MacroEventInfo(InfoLevel, CliEventABC):
msg: str

def cli_msg(self) -> str:
return self.msg


@dataclass
class MacroEventDebug(DebugLevel, CliEventABC):
msg: str

def cli_msg(self) -> str:
return self.msg


# since mypy doesn't run on every file we need to suggest to mypy that every
# class gets instantiated. But we don't actually want to run this code.
# making the conditional `if False` causes mypy to skip it as dead code so
Expand All @@ -122,3 +138,5 @@ def cli_msg(self) -> str:
ManifestChecked()
ManifestFlatGraphBuilt()
ReportPerformancePath(path='')
MacroEventInfo(msg='')
MacroEventDebug(msg='')

0 comments on commit 35dcd4d

Please sign in to comment.