question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[CT-172] `--quiet` flag for run-operations

See original GitHub issue

Describe the feature

Currently, when you run run-operation you get the output of your macro after a few lines of text, for example:

Running with dbt=0.19.1
[WARNING]: Configuration paths exist in your dbt_project.yml file which do not apply to any resources.
There are 2 unused configuration paths:
- seeds
- snapshots

{macro output here}

I’m proposing a --quiet flag for run-operation that would remove the Running with dbt and any other warnings, leaving just the output of the macro.

Describe alternatives you’ve considered

I’ve previously wrapped calls to run-operation in bash script which trims the first line from the output, however when warnings are triggered (like the example above) it’s hard to tell in advance how many lines to trim.

Who will this benefit?

Anyone who uses the codegen macro (and similar macros) outside of dbt cloud

Are you interested in contributing this feature?

Yes — I’ve poked around the logger code but couldn’t see a straightforward way of doing this, but I’m open to trying with some input!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:18 (17 by maintainers)

github_iconTop GitHub Comments

2reactions
emmyoopcommented, Feb 7, 2022

@jaypeedevlin and @ehmartens the team and I have come up with an even more robust solution that will fix a few different situations. While my previous solution would work, this is better long term. #4687 recently requested the ability to silence logs to stdout as well.

The general solution is two fold.

First, add a flag --quiet whose sole purpose is to silence logs to stdout. This will be a global flag that is added to flags.py and main.py (following the example of --debug or --log-cache-events). In this new context where it’s only purpose is to not log anything to stdout, --quiet makes more sense as the flag name.

No new event base classes need to be created with this route either. We can leverage the already existing NoStdOut.

You will need to modify the below code to swallow the log for flags.QUIET similar to what we do for flags.DEBUG on line 352. https://github.com/dbt-labs/dbt-core/blob/2d0b975b6c2023cde219f0a045709a1fa5c6c840/core/dbt/events/functions.py#L349-L367

Second, let’s add a {{ print() }} function to macros! It will be very similar to {{ log() }}. The difference being that print is not a log statement, it will just print to stdout.

To do this, you can copy the approach we have for log. It should always just print to stdout.

https://github.com/dbt-labs/dbt-core/blob/2d0b975b6c2023cde219f0a045709a1fa5c6c840/core/dbt/context/base.py#L475-L494

These two changes (and a change to codegen to use this new print statement) would result in dbt run-operation generate_source --args '{"schema_name": "jaffle_shop", "database_name": "raw"}' to print to stdout any print statements in generate_source but no logs. Logs would however still be written to the file.

2reactions
emmyoopcommented, Feb 4, 2022

After giving this a bit more thought I’m thinking we may want to go down the path of a new log level. I’d like to think through the implications of it a bit more before saying we should definitely go that route. But wanted to put a note here so @jaypeedevlin and @ehmartens don’t start down the Loud path unnecessarily (yet).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Quiet - IBM
The quiet option limits the number of messages that are displayed on your screen during processing.. For example, when you run the incremental,...
Read more >
How to set --quiet flag by default in git? [duplicate]
You can't set the quiet flag for all your commands in the gitconfig. As @torek mentioned, there is no way to set built-in...
Read more >
american-flag - Loud And Quiet
american-flag. ↑. Loud And Quiet. Moderately successful since 2005. •. Subscribe · Shorts · Interviews · Podcasts · Reviews.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found