Skip to content

Commit 1a32f25

Browse files
Fix(dbt): Use the info to control logging for dbt log builtin
1 parent 13ae8e3 commit 1a32f25

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

sqlmesh/dbt/builtin.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,13 @@ def env_var(name: str, default: t.Optional[str] = None) -> t.Optional[str]:
170170

171171

172172
def log(msg: str, info: bool = False) -> str:
173-
logger.debug(msg)
173+
if info:
174+
# Write to both log file and stdout
175+
logger.info(msg)
176+
print(msg)
177+
else:
178+
logger.debug(msg)
179+
174180
return ""
175181

176182

tests/dbt/test_transformation.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -856,16 +856,33 @@ def test_run_query(sushi_test_project: Project, runtime_renderer: t.Callable):
856856

857857

858858
@pytest.mark.xdist_group("dbt_manifest")
859-
def test_logging(sushi_test_project: Project, runtime_renderer: t.Callable):
859+
def test_logging(sushi_test_project: Project, runtime_renderer: t.Callable, capsys):
860860
context = sushi_test_project.context
861861
assert context.target
862862
engine_adapter = context.target.to_sqlmesh().create_engine_adapter()
863863
renderer = runtime_renderer(context, engine_adapter=engine_adapter)
864864

865865
logger = logging.getLogger("sqlmesh.dbt.builtin")
866-
with patch.object(logger, "debug") as mock_logger:
866+
867+
# Test log with info=False (default) which should only log with debug
868+
with patch.object(logger, "debug") as mock_debug, patch.object(logger, "info") as mock_info:
867869
assert renderer('{{ log("foo") }}') == ""
868-
assert "foo" in mock_logger.call_args[0][0]
870+
mock_debug.assert_called_once()
871+
assert "foo" in mock_debug.call_args[0][0]
872+
mock_info.assert_not_called()
873+
874+
captured = capsys.readouterr()
875+
assert "foo" not in captured.out
876+
877+
# Test log with info=True, now should log with info and also print to stdout
878+
with patch.object(logger, "debug") as mock_debug, patch.object(logger, "info") as mock_info:
879+
assert renderer('{{ log("output to be logged with info", info=true) }}') == ""
880+
mock_info.assert_called_once()
881+
assert "output to be logged with info" in mock_info.call_args[0][0]
882+
mock_debug.assert_not_called()
883+
884+
captured = capsys.readouterr()
885+
assert "output to be logged with info" in captured.out
869886

870887
with patch.object(logger, "debug") as mock_logger:
871888
assert renderer('{{ print("bar") }}') == ""

0 commit comments

Comments
 (0)