diff --git a/.changes/unreleased/Fixes-20230615-102639.yaml b/.changes/unreleased/Fixes-20230615-102639.yaml new file mode 100644 index 00000000000..f666f5afb40 --- /dev/null +++ b/.changes/unreleased/Fixes-20230615-102639.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Fix accidental propagation of log messages to root logger. +time: 2023-06-15T10:26:39.139421-04:00 +custom: + Author: peterallenwebb + Issue: "7872" diff --git a/.changes/unreleased/Fixes-20230615-110538.yaml b/.changes/unreleased/Fixes-20230615-110538.yaml new file mode 100644 index 00000000000..af0d7c020aa --- /dev/null +++ b/.changes/unreleased/Fixes-20230615-110538.yaml @@ -0,0 +1,7 @@ +kind: Fixes +body: Fixed an issue which blocked debug logging to stdout with --log-level debug, + unless --debug was also used. +time: 2023-06-15T11:05:38.053387-04:00 +custom: + Author: peterallenwebb + Issue: "7872" diff --git a/core/dbt/events/eventmgr.py b/core/dbt/events/eventmgr.py index 55dfbd203f0..e52dae706b5 100644 --- a/core/dbt/events/eventmgr.py +++ b/core/dbt/events/eventmgr.py @@ -110,6 +110,7 @@ def _get_python_log_for_handler(self, handler: logging.Handler): log.setLevel(_log_level_map[self.level]) handler.setFormatter(logging.Formatter(fmt="%(message)s")) log.handlers.clear() + log.propagate = False log.addHandler(handler) return log diff --git a/core/dbt/events/functions.py b/core/dbt/events/functions.py index 21bc4d3c0b3..9a1c2340a2d 100644 --- a/core/dbt/events/functions.py +++ b/core/dbt/events/functions.py @@ -39,14 +39,18 @@ def setup_event_logger(flags, callbacks: List[Callable[[EventMsg], None]] = []) else: if flags.LOG_LEVEL != "none": line_format = _line_format_from_str(flags.LOG_FORMAT, LineFormat.PlainText) - log_level = EventLevel.DEBUG if flags.DEBUG else EventLevel(flags.LOG_LEVEL) + log_level = ( + EventLevel.ERROR + if flags.QUIET + else EventLevel.DEBUG + if flags.DEBUG + else EventLevel(flags.LOG_LEVEL) + ) console_config = _get_stdout_config( line_format, - flags.DEBUG, flags.USE_COLORS, log_level, flags.LOG_CACHE_EVENTS, - flags.QUIET, ) EVENT_MANAGER.add_logger(console_config) @@ -81,11 +85,9 @@ def _line_format_from_str(format_str: str, default: LineFormat) -> LineFormat: def _get_stdout_config( line_format: LineFormat, - debug: bool, use_colors: bool, level: EventLevel, log_cache_events: bool, - quiet: bool, ) -> LoggerConfig: return LoggerConfig( @@ -97,8 +99,6 @@ def _get_stdout_config( filter=partial( _stdout_filter, log_cache_events, - debug, - quiet, line_format, ), output_stream=sys.stdout, @@ -107,16 +107,11 @@ def _get_stdout_config( def _stdout_filter( log_cache_events: bool, - debug_mode: bool, - quiet_mode: bool, line_format: LineFormat, msg: EventMsg, ) -> bool: - return ( - (msg.info.name not in ["CacheAction", "CacheDumpGraph"] or log_cache_events) - and (EventLevel(msg.info.level) != EventLevel.DEBUG or debug_mode) - and (EventLevel(msg.info.level) == EventLevel.ERROR or not quiet_mode) - and not (line_format == LineFormat.Json and type(msg.data) == Formatting) + return (msg.info.name not in ["CacheAction", "CacheDumpGraph"] or log_cache_events) and not ( + line_format == LineFormat.Json and type(msg.data) == Formatting ) @@ -147,11 +142,9 @@ def _get_logbook_log_config( ) -> LoggerConfig: config = _get_stdout_config( LineFormat.PlainText, - debug, use_colors, - EventLevel.DEBUG if debug else EventLevel.INFO, + EventLevel.ERROR if quiet else EventLevel.DEBUG if debug else EventLevel.INFO, log_cache_events, - quiet, ) config.name = "logbook_log" config.filter = ( @@ -183,7 +176,7 @@ def cleanup_event_logger(): EVENT_MANAGER.add_logger( _get_logbook_log_config(False, True, False, False) # type: ignore if ENABLE_LEGACY_LOGGER - else _get_stdout_config(LineFormat.PlainText, False, True, EventLevel.INFO, False, False) + else _get_stdout_config(LineFormat.PlainText, True, EventLevel.INFO, False) ) # This global, and the following two functions for capturing stdout logs are