Skip to content

cln-plugin: fix structured logging, field quoting, and re-init panic - #9761

Open
daywalker90 wants to merge 1 commit into
ElementsProject:masterfrom
daywalker90:cln-plugin-logging-regression-tests
Open

daywalker90 wants to merge 1 commit into
ElementsProject:masterfrom
daywalker90:cln-plugin-logging-regression-tests

Conversation

@daywalker90

Copy link
Copy Markdown
Collaborator

Fix three bugs in plugins/src/logging.rs:

  1. LoggingLayer::on_event returned early whenever extractor.msg was None, silently dropping structured tracing events that only carry fields (e.g. tracing::info!(peer_id = "alice", amount = 1000)). Format field-only events as [k=v, ...] and only return early when both message and fields are empty.
  2. LogExtract only implemented Visit::record_debug, so bare &str / String fields fell back to Debug (which quotes strings) and were quoted a second time as peer=""alice"", while numbers and booleans were quoted as strings. Implement the typed Visit methods on LogExtract so strings, % (Display), and ? (Debug) fields are single-quoted while numeric and boolean fields are unquoted.
  3. trace::init called .init() (which panics if a global subscriber is already installed) and spawned the writer task before subscriber registration. Switch to .try_init()? and only spawn the writer task after registration succeeds.

Add unit tests covering structured events without a message, quoting of strings/Display/numbers/booleans, and duplicate logging::init calls.

Changelog-Fixed: cln-plugin: stop dropping structured tracing events without a message field, fix field quoting (single-quote strings/Display/Debug fields, leave numbers/booleans unquoted), and return an error instead of panicking on duplicate logger initialization.

Fix three bugs in `plugins/src/logging.rs`:

1. `LoggingLayer::on_event` returned early whenever `extractor.msg` was
   `None`, silently dropping structured `tracing` events that only carry
   fields (e.g. `tracing::info!(peer_id = "alice", amount = 1000)`).
   Format field-only events as `[k=v, ...]` and only return early when
   both `message` and `fields` are empty.
2. `LogExtract` only implemented `Visit::record_debug`, so bare `&str` /
   `String` fields fell back to `Debug` (which quotes strings) and were
   quoted a second time as `peer=""alice""`, while numbers and booleans
   were quoted as strings. Implement the typed `Visit` methods on
   `LogExtract` so strings, `%` (`Display`), and `?` (`Debug`) fields
   are single-quoted while numeric and boolean fields are unquoted.
3. `trace::init` called `.init()` (which panics if a global subscriber
   is already installed) and spawned the writer task before subscriber
   registration. Switch to `.try_init()?` and only spawn the writer task
   after registration succeeds.

Add unit tests covering structured events without a `message`, quoting
of strings/`Display`/numbers/booleans, and duplicate `logging::init`
calls.

Changelog-Fixed: cln-plugin: stop dropping structured `tracing` events without a `message` field, fix field quoting (single-quote strings/`Display`/`Debug` fields, leave numbers/booleans unquoted), and return an error instead of panicking on duplicate logger initialization.
@daywalker90
daywalker90 requested a review from cdecker as a code owner November 24, 2026 15:20

This branch has not been deployed

No deployments
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