dbt-labs / dbt-core

dbt enables data analysts and engineers to transform their data using the same practices that software engineers use to build applications.

Home Page:https://getdbt.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] print in jinja do not go through event system

ChenyuLInx opened this issue · comments

Is this a new bug in dbt-core?

  • I believe this is a new bug in dbt-core
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

If a user uses the print in the Jinja context, this print will go to stdout directly instead of going through the dbt-core's event system.

This would lead to things printed in jinja do not follow --log-format json config.

Expected Behavior

print in jinja follow dbt-core's flag --log-format

Steps To Reproduce

Run a run operation with a macro that has print inside and use --log-format json at the same time.
You will see dbt-core logs are in json but the things printed in jinja is in plain text.

Relevant log output

No response

Environment

- OS:
- Python:
- dbt:

Which database adapter are you using with dbt?

No response

Additional Context

No response

An example

{% macro test() %}
    {{ print(1234)}}
    {{ return(1233434) }}
{% endmacro %}

When user specify --log-format json, we expect 1234 should be printed in a json format line and maybe logged in dbt.log as well?

The customer uses "generate_source" from codegen dbt package.

We could use log(info=True) to swap this out.
Things to watch for: can we not add dates in front of the printed line.

Closing in favor of 8756 since it is the same issue and have a more detailed AC.