From f23ae56693c931e36028a61ea1b11ffdd25762e2 Mon Sep 17 00:00:00 2001 From: Maxime Carbonneau-Leclerc <3360483+maxi297@users.noreply.github.com> Date: Fri, 6 Sep 2024 14:30:36 -0400 Subject: [PATCH] bug(airbyte-cdk) Fix extras not being printed (#45198) --- airbyte-cdk/python/airbyte_cdk/logger.py | 2 +- airbyte-cdk/python/unit_tests/test_logger.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/airbyte-cdk/python/airbyte_cdk/logger.py b/airbyte-cdk/python/airbyte_cdk/logger.py index 72673dcfa8f7..da3f869f2f32 100644 --- a/airbyte-cdk/python/airbyte_cdk/logger.py +++ b/airbyte-cdk/python/airbyte_cdk/logger.py @@ -53,7 +53,7 @@ class AirbyteLogFormatter(logging.Formatter): def format(self, record: logging.LogRecord) -> str: """Return a JSON representation of the log message""" airbyte_level = self.level_mapping.get(record.levelno, "INFO") - if airbyte_level == "DEBUG": + if airbyte_level == Level.DEBUG: extras = self.extract_extra_args_from_record(record) debug_dict = {"type": "DEBUG", "message": record.getMessage(), "data": extras} return filter_secrets(json.dumps(debug_dict)) diff --git a/airbyte-cdk/python/unit_tests/test_logger.py b/airbyte-cdk/python/unit_tests/test_logger.py index df44cd22e006..3b6db8b89232 100644 --- a/airbyte-cdk/python/unit_tests/test_logger.py +++ b/airbyte-cdk/python/unit_tests/test_logger.py @@ -51,12 +51,15 @@ def test_level_transform(logger, caplog): def test_debug(logger, caplog): # Test debug logger in isolation since the default logger is initialized to TRACE (15) instead of DEBUG (10). + formatter = AirbyteLogFormatter() debug_logger = logging.getLogger("airbyte.Debuglogger") debug_logger.setLevel(logging.DEBUG) - debug_logger.debug("Test debug 1") + debug_logger.debug("Test debug 1", extra={"extra_field": "extra value"}) record = caplog.records[0] - assert record.levelname == "DEBUG" - assert record.message == "Test debug 1" + formatted_record = json.loads(formatter.format(record)) + assert formatted_record["type"] == "DEBUG" + assert formatted_record["message"] == "Test debug 1" + assert formatted_record["data"]["extra_field"] == "extra value" def test_default_debug_is_ignored(logger, caplog):