Skip to content
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 aws_lambda_powertools/logging/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ def _create_and_flush_log_record(self, log_line: dict) -> None:
fn=log_line["filename"],
lno=log_line["line"],
msg=log_line["msg"],
args=(),
args=log_line.get("args", ()),
exc_info=log_line["exc_info"],
func=log_line["function"],
extra=log_line["extra"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,3 +568,19 @@ def test_warning_when_alc_less_verbose_than_buffer(stdout, monkeypatch):
# THEN another warning should be emitted about ALC and buffer level mismatch
with pytest.warns(PowertoolsUserWarning, match="Advanced Logging Controls*"):
logger.flush_buffer()


def test_flush_buffer_preserves_percent_style_formatting(stdout, service_name, monkeypatch):
monkeypatch.setenv(constants.XRAY_TRACE_ID_ENV, "1-67c39786-5908a82a246fb67f3089263f")

# GIVEN A logger configured with a buffer
logger_buffer_config = LoggerBufferConfig(max_bytes=10240)
logger = Logger(level="DEBUG", service=service_name, stream=stdout, buffer_config=logger_buffer_config)

# WHEN Logging a message with percent-style formatting
logger.debug("user=%s count=%d", "alice", 42)
logger.flush_buffer()

# THEN The flushed log should contain the interpolated message
log = capture_multiple_logging_statements_output(stdout)
assert log[0]["message"] == "user=alice count=42"