如何在dbt宏或日志中添加时间戳

huangapple go评论96阅读模式
英文:

How to Add a timestamp within dbt macro or log

问题

我想在我的宏日志中添加一个时间戳,显示本地地点的当前日期和时间。我尝试将run_started_at函数放在日志内外,但不起作用。我更喜欢将其放在日志内。即'操作完成 01:10:2023 11:30' 以下是我所做的工作:

  1. {% macro create_local_database(username, reset_environment = false) %}
  2. {% set setup_script1 %}
  3. {%- if reset_environment == false -%}
  4. CREATE DATABASE ANALYTICS_LOCAL_MART_{{username}}
  5. {% do log('操作完成 ' ~ run_started_at.strftime('%Y-%m-%d %H:%M')) %}
  6. {%- endif -%}
  7. {% endset %}
  8. {% 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;

  1. {% macro create_local_database(username, reset_environment = false) %}
  2. {% set setup_script1 %}
  3. {%- if reset_environment == false -%}
  4. CREATE DATABASE ANALYTICS_LOCAL_MART_{{username}}
  5. {% do log('Operation Completed', True) %} {{ run_started_at.strftime("%Y-%m-%d") }}
  6. {%- endif -%}
  7. {% endset %}
  8. {% 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()

  1. {{ log(this ~ " (" ~ run_started_at.strftime('%Y-%m-%d') ~ "): " ~ msg, true) }}
  2. {%- endmacro -%}```
  3. <details>
  4. <summary>英文:</summary>
  5. 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 -%}

  1. </details>

huangapple
  • 本文由 发表于 2023年1月6日 11:00:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75026536.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定