Uh oh!
There was an error while loading. Please reload this page.
Logging and spans via thread-local storage - #4223
Conversation
ldk-reviews-bot
commented
Nov 13, 2025
👋 Hi! I see this is a draft PR. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@## main #4223 +/- ##
=======================================
Coverage 89.33% 89.34% =======================================
Files 180 180 Lines 139042 139082 +40 Branches 139042 139082 +40 =======================================
+ Hits 124219 124264 +45 + Misses 12196 12193 -3 + Partials 2627 2625 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
TheBlueMatt
commented
Nov 17, 2025
I played with this a bit, sadly Rust doesn't allow you to convert an arbitrary (
(of course the [1] https://git.bitcoin.ninja/?p=rust-lightning;a=shortlog;h=refs/heads/claude/2025-11-dyn-logger [2] |
joostjager
commented
Nov 17, 2025
I've tried to make it work on top of your First I thought you wanted to bound everything on Proc macro for logger scope is interesting, and can indeed be extended with a node id in testing. |
TheBlueMatt
commented
Nov 17, 2025
The type passed to |
I had tried that, but it didn't work. Same sized error. Pushed the commit. Maybe I am doing something wrong. |
I am wondering what the performance implications are of the logger scope. Just adding a node id in TLS would test-only, but storing the logger instance itself is production code that wouldn't be running if there was a global logger instead. |
TheBlueMatt
commented
Nov 17, 2025
I don't think its going to be material in either direct. Storing a |
TheBlueMatt
commented
Nov 17, 2025
Right, looks like claude just forgot to update the |
TheBlueMatt
commented
Nov 17, 2025
Oh, claude didn't update any of the references to dyn lol. Dumb LLMs just ignore half of what you tell them, I hadn't bothered to look at what it did, either. Anyway, gotta update all those bounds! |
joostjager
commented
Nov 20, 2025
With bound I started a bit of creative search/replace across the repo to do a sweeping conversion (https://github.com/lightningdevkit/rust-lightning/compare/main...joostjager:rust-lightning:dyn-logger?expand=0). Needs a bit more work. It's probably not necessary for deciding on the direction we want to take this to. |
ee40265 to
d3f7e4dCompareReduce boiler plate for logging, and allow quick insertion of log statements anywhere without first threading through a logger instance and associated type parameter.
Demonstrating how the proc macro can be used to set a thread-local logger at a public entry point. The scope name is also picked up and logged via log statements that still have an explicit logger instance.
joostjager
commented
Dec 4, 2025
Sadly it seems that thread-local storage isn't compatible with no std. It's very unfortunate that I realized that only now that this PR is nearly finished. Spans can probably be implemented without thread-local storage, but getting rid of the logger parameters seems to be impossible. Even a global logger is problematic in no std because it requires the logger to be |
joostjager
commented
Mar 20, 2026
I don't see this happening as long as we keep the current logging system |
This PR adds the ability to open a logger scope that stores the
Loggerinstance in thread-local storage. This avoids the need to thread through a logger and associated type parameter to every method that needs to log.A logger scope can also be given a name and logging
Records now contain the names of the surrounding scopes.Example log output: