Repository navigation
cln-plugin: fix structured logging, field quoting, and re-init panic - #9761
Open
daywalker90 wants to merge 1 commit into
Open
daywalker90 wants to merge 1 commit into
daywalker90 wants to merge 1 commit into
Conversation
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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix three bugs in
plugins/src/logging.rs:LoggingLayer::on_eventreturned early wheneverextractor.msgwasNone, silently dropping structuredtracingevents 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 bothmessageandfieldsare empty.LogExtractonly implementedVisit::record_debug, so bare&str/Stringfields fell back toDebug(which quotes strings) and were quoted a second time aspeer=""alice"", while numbers and booleans were quoted as strings. Implement the typedVisitmethods onLogExtractso strings,%(Display), and?(Debug) fields are single-quoted while numeric and boolean fields are unquoted.trace::initcalled.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 duplicatelogging::initcalls.Changelog-Fixed: cln-plugin: stop dropping structured
tracingevents without amessagefield, fix field quoting (single-quote strings/Display/Debugfields, leave numbers/booleans unquoted), and return an error instead of panicking on duplicate logger initialization.