Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CT-2703] [Bug] DBT when using Programmatic invocations with callbacks overrides stdout to file log level #7872

Closed
2 tasks done
stevensnicholas opened this issue Jun 14, 2023 · 2 comments · Fixed by #7882
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@stevensnicholas
Copy link

stevensnicholas commented Jun 14, 2023

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

When using the dbtRunner with a callback function overrides the level of the current stdout to the level at which the file logging is set if logging.basicConfig was used.

The stdout is being given debug log, even when the log level is set to info

Expected Behavior

Only the log level info or the level set by --log-level are printed to stout

Steps To Reproduce

The below code should work on a simple DBT project

import logging
logger = logging.getLogger(__name__)
logger.info("This should not be seen")
logging.basicConfig(level=logging.INFO)
logger.warning("This should be seen")
logger.debug("This is a debug message")

from dbt.events.base_types import EventMsg
from dbt.contracts.graph.manifest import Manifest
from dbt.cli.main import dbtRunner, dbtRunnerResult
def dbt_callback(event: EventMsg) -> None:
    return
res: dbtRunnerResult = dbtRunner(callbacks=[dbt_callback]).invoke(["--log-level","info","--log-level-file","debug","parse"])

Relevant log output

this is the first few lines from STDOUT, not the log file. I have removed the log path and profiles_dir.

:25:40.506397 [info ] [MainThread]: Running with dbt=1.5.1
DEBUG:file_log:16:25:40.508398 [debug] [MainThread]: running dbt with arguments {'printer_width': '80', 'indirect_selection': 'eager', 'write_json': 'True', 'log_cache_events': 'False', 'partial_parse': 'True', 'cache_selected_only': 'False', 'warn_error': 'None', 'version_check': 'True', 'debug': 'False', 'log_path': 'MANUALLY_REMOVED', 'fail_fast': 'False', 'profiles_dir': 'MANUALLY_REMOVED', 'use_colors': 'True', 'use_experimental_parser': 'False', 'no_print': 'None', 'quiet': 'False', 'log_format': 'default', 'introspect': 'True', 'warn_error_options': 'WarnErrorOptions(include=[], exclude=[])', 'static_parser': 'True', 'target_path': 'None', 'send_anonymous_usage_stats': 'True'}

Environment

- OS: Windows 10
- Python: 3.10.11
- dbt: 1.5.1 (Redshift 1.5.4)

Which database adapter are you using with dbt?

redshift

Additional Context

No response

@stevensnicholas stevensnicholas added bug Something isn't working triage labels Jun 14, 2023
@github-actions github-actions bot changed the title [Bug] DBT when using Programmatic invocations with callbacks overrides stdout to file log level [CT-2703] [Bug] DBT when using Programmatic invocations with callbacks overrides stdout to file log level Jun 14, 2023
@peterallenwebb
Copy link
Contributor

@stevensnicholas Thank you for opening this issue. I've opened a PR which would fix this issue in dbt 1.6. In the meantime, the only way to sidestep this behavior might be to configure your logger directly, rather than calling basicConfig(), which adds a stdout logger to the root logger.

@dbeatty10 dbeatty10 removed the triage label Jun 15, 2023
@stevensnicholas
Copy link
Author

stevensnicholas commented Jun 16, 2023

Thanks, that PR was fast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants