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

bug(airbyte-cdk) Fix extras not being printed #45198

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion airbyte-cdk/python/airbyte_cdk/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
9 changes: 6 additions & 3 deletions airbyte-cdk/python/unit_tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading