英文:
How to Add a timestamp within dbt macro or log
问题
我想在我的宏日志中添加一个时间戳,显示本地地点的当前日期和时间。我尝试将run_started_at函数放在日志内外,但不起作用。我更喜欢将其放在日志内。即'操作完成 01:10:2023 11:30' 以下是我所做的工作:
{% macro create_local_database(username, reset_environment = false) %}
{% set setup_script1 %}
{%- if reset_environment == false -%}
CREATE DATABASE ANALYTICS_LOCAL_MART_{{username}}
{% do log('操作完成 ' ~ run_started_at.strftime('%Y-%m-%d %H:%M')) %}
{%- endif -%}
{% endset %}
{% endmacro %}
我想要一个包含消息和时间戳的宏日志。
英文:
I want to add a timestamp to my macro log that shows the current date and time of the local place. I tried to place the run_started_at function in and out of the log, but it doesn't work. I prefer to have inside the log. ie,'Operation Completed 01:10:2023 11:30' Below are the works I have done;
{% macro create_local_database(username, reset_environment = false) %}
{% set setup_script1 %}
{%- if reset_environment == false -%}
CREATE DATABASE ANALYTICS_LOCAL_MART_{{username}}
{% do log('Operation Completed', True) %} {{ run_started_at.strftime("%Y-%m-%d") }}
{%- endif -%}
{% endset %}
{% endmacro %}
I would like to have a macro log that includes the message and timestamp.
答案1
得分: 1
Append the timestamp to the string you send to log()
{{ log(this ~ " (" ~ run_started_at.strftime('%Y-%m-%d') ~ "): " ~ msg, true) }}
{%- endmacro -%}```
<details>
<summary>英文:</summary>
Just append the timestamp to the string you send to `log()`
{%- macro logt(msg) -%}
{{ log(this ~ " (" ~ run_started_at.strftime('%Y-%m-%d') ~ "): " ~ msg, true) }}
{%- endmacro -%}
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论