Skip to content

Add configurable logger #393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

domZippilli
Copy link

@domZippilli domZippilli commented Oct 28, 2024

Description

Adds logger configuration to ldk-node.

Motivation

The first impulse for this was to be able to write to stdout, as that's more desirable for some containerized infrastructure. But rather than add a specific stdout implementation, we thought it better to make this extensible to write to arbitrary destinations (for example, a network log ingester). This additionally has the benefit of letting you customize how the writing happens; for example the tracing-appender crate uses an mpsc for writers, with a single thread performing all the actual I/O off of the queue.

Details

The PR has three commits:

@domZippilli domZippilli force-pushed the 2024-10-configurable-logger branch from b3761eb to b0e7fef Compare October 28, 2024 16:58
@tnull
Copy link
Collaborator

tnull commented Oct 28, 2024

Thanks for looking into this and I def. agree we need to add the capability for custom loggers (see #309) but I'm not sure we want to go with the approach chosen here.

As described over at #309, we probably want to try using the log crate facade if possible (at least for the Rust side), to which end we will try to take an optional dependency upstream. Moreover, the custom logger interface will need to be exposable via UniFFI bindings, which doesn't work with the approach chosen here. We also want to make the FilesystemLogger play nicely with OS-level tooling such as logrotate as a first step, which would necessitate adding signal handling if we keep the open file handle around, which this PR also adds.

Let me know if that makes sense and also what additional requirements you see for a custom logger interface. If you intend to keep working on this, you might want to coordinate with @enigbe which just recently indicated interest in working on it / #309, too.

@domZippilli
Copy link
Author

domZippilli commented Oct 28, 2024

Ah, I see. I was trying to avoid taking a dependency, but if you've already decided you want to use log, then that makes sense. We also wanted to avoid chasing generics all over the code, so the Fn trait objects were good, at least for the Rust side.

We originally did this in our local fork, as we can only see stdout logs right now. We can keep running with our fork until #309 is resolved.

As far as requirements I'd like to see for #309:

  • I'd like to be able to do structured logging. JSON, in our case, but full control over formatting would be best.
  • I'd like to be able to specify the device I'm writing to. Originally I did this with a dyn Writer, but for FFI you might need to do something else. At a minimum, I would need stdout.
  • I'd like to be able to specify how the writing happens. A non-blocking writer like I mentioned is important for high volume logging.

eta:

We also want to make the FilesystemLogger play nicely with OS-level tooling such as logrotate as a first step, which would necessitate adding signal handling if we keep the open file handle around, which this PR also adds.

That would be very trivially reversed, and that should hold true for any implementation that's extensible enough. Maybe that's a good litmus test for customization, as well.

@tnull
Copy link
Collaborator

tnull commented Oct 28, 2024

but if you've already decided you want to use log, then that makes sense.

Yes, we probably will go this way at least here in LDK Node, but possibly also at least optionally upstream as users keep stumbling across the fact that LDK doesn't use log, i.e., especially in larger projects with multiple producers LDK stands out as the one logging to its own thing while all other logs are in a single stream. So IMO we should at least try to support it in LDK also.

We also wanted to avoid chasing generics all over the code, so the Fn trait objects were good, at least for the Rust side.

Right, you can also expose trait objects arguments via Uniffi, but they need to adhere to some rules, i.e., we'll likely need something like set_custom_logger(&self, logger: Arc<dyn CustomLogger + Send + Sync>) method on the Builder or similar.

As far as requirements I'd like to see for #309:

Cool, thanks. Will keep these in mind! My goal for now is to end up with a slightly improved FilesystemLogger and a pluggable interface so that you can do whatever you want in your logger implementation.

@domZippilli
Copy link
Author

something like set_custom_logger(&self, logger: Arc<dyn CustomLogger + Send + Sync>) method on the Builder

Heh, I tried this as well, too bad I tossed the commit. I think that would work as well, although it left me writing some awkward documentation ... along the lines of, "If you specify this, these other logging fields from config are ignored."

@domZippilli
Copy link
Author

possibly also at least optionally upstream as users keep stumbling across the fact that LDK doesn't use log

P.S. -- If you do this, give some thought to the tracing user experience. Especially if you're targeting larger nodes, I think a lot of them would end up trying to drop-in tracing in place of log.

@tnull
Copy link
Collaborator

tnull commented Oct 29, 2024

P.S. -- If you do this, give some thought to the tracing user experience. Especially if you're targeting larger nodes, I think a lot of them would end up trying to drop-in tracing in place of log.

Yeah, that's a good point, maybe even more so regarding the upstream changes as we might need tracing to accommodate our structured logging macros there. That said, there also is tracing-log which should users that need it at least rudimentary compatibility if we use log.

@tnull tnull mentioned this pull request Nov 8, 2024
@enigbe enigbe mentioned this pull request Nov 12, 2024
7 tasks
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.

2 participants