8000 log: format a message that has no arguments after it by benface · Pull Request #687 · not-fl3/miniquad · GitHub
[go: up one dir, main page]

Skip to content

log: format a message that has no arguments after it - #687

Open
benface wants to merge 2 commits into
not-fl3:masterfrom
benface:log-format-literal
Open

benface wants to merge 2 commits into
not-fl3:masterfrom
benface:log-format-literal

Conversation

@benface
@benface benface commented Oct 10, 2026 •
Copy link
Copy Markdown
Contributor

Why

log!'s first arm matches a string with nothing after it. It checks the string with format!, throws the result away and logs the string itself. The arm predates inline format arguments, which format! accepts, so this compiles and logs failed to load {path}:

let path = "assets/icon.png";
warn!("failed to load {path}");

An escaped brace comes out doubled too: warn!("{{}}") logs {{}} rather than {}. macroquad re-exports these macros as macroquad::logging, so its users hit the same thing.

Change

The arm is gone. A string with nothing after it now goes through the same format! as one with arguments, so it prints as println! would. test_logs logs an inline argument at each level and an escaped brace. Under cfg(test), the desktop logger also records each message, and the test checks them.

The arm spared those messages an allocation, but the Android, wasm and iOS loggers copy every message into a C string or an NSString anyway.

Verification

  • cargo test --features log-impl test_logs passes with this change. With the old arm put back, it fails: the logger gets info: {value} at each level and {{value}}, not info: 1 and {value}.
  • cargo check --features log-impl passes for aarch64-apple-darwin, aarch64-apple-ios, aarch64-apple-tvos, aarch64-linux-android and wasm32-unknown-unknown.

🤖 Generated with Claude Code

benface and others added 2 commits October 10, 2026 03:05
`log!`'s first arm took a lone string, checked it with `format!` and
then logged the string itself. That arm predates inline format
arguments: `warn!("failed to load {path}")` compiles, and the check
formats it correctly, but the log shows `failed to load {path}`. An
escaped brace, as in `"{{"`, came out doubled too.

The arm is gone, so a lone string goes through the same `format!` as
a string with arguments after it, and prints as `println!` would.
`test_logs` now logs an inline argument at each level.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`test_logs` printed its messages without checking them, so it passed
with the lone-string bug in place. The desktop logger now also records
each message under `cfg(test)`, and the test compares them with what
`format!` gives, an escaped brace included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0