Skip to content

Use log facade and log4rs for logging. #44

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

Closed
wants to merge 1 commit into from

Conversation

G8XSU
Copy link
Contributor

@G8XSU G8XSU commented Feb 13, 2025

  • Pending Ldk-node upgrade, hence draft.

@@ -4,6 +4,8 @@ version = "0.1.0"
edition = "2021"

[dependencies]
log = "0.4.25"
log4rs = "1.3.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has a quite a big dependency tree, also single-author stuff like https://github.com/sfackler/rust-log-mdc.
Are we sure there is no feasible alternative? Or do we even want to implement a bare bones logger ourselves, it's really straightforward (see the MockLogger in lightningdevkit/ldk-node#463).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabling all features does cut down the dep tree significantly.
And if we don't use rolling_file, we can cut down further dependencies. There are alternative implementations but log4rs seems pretty widely used and can serve our needs for now.

We will evaluate if we should replace everything with tracing but for now this is a good crate to depend on for basic logging. I don't feel we should invest too much effort into custom logging implementation as of now.

for [rust-log-mdc](https://github.com/sfackler/rust-log-mdc/tree/master), it looks like it is a simple thread local map for variables.

Copy link
Collaborator

@tnull tnull Mar 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, sorry for the delay here, this kinda fell of my radar for a bit.

Disabling all features does cut down the dep tree significantly.

Cool, it's still considerable, and for some of them I don't know why a simple logger would need to use them...

We will evaluate if we should replace everything with tracing but for now this is a good crate to depend on for basic logging. I don't feel we should invest too much effort into custom logging implementation as of now.

Okay, I'm just not sure what features we really need that would warrant taking on the downstream dependencies of log4rs vs. simpler solutions like simplelog for example. I guess if we may reconsider the choice in the future, we may be fine with reducing dependencies/features for now. But IMO we really should get back to it and replace it with our own implementation if we don't end up switching to tracing, for example.

That said, especially if we're considering this to be just the initial step to be revisited soon, I don't know why we don't opt for the simplest implementation, that doesn't introduce a considerable dependency tree?

for [rust-log-mdc](https://github.com/sfackler/rust-log-mdc/tree/master), it looks like it is a simple thread local map for variables.

Well, I don't care so much about what it is, but that it is crate with no community besides a single author, which means they could of course unilaterally decide to publish a malicious version (not saying this particular author might ever do that, of course), and the chances of anybody catching that (in time) would be very very slim.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplelog doesn't work for us as an initial step.
Ldk server will be a long running process, hence i consider rolling file based logging a bare minimum for now.
Moreover, simplelog is also a single author crate and less widely used than log4rs.

I guess if we may reconsider the choice in the future, we may be fine with reducing dependencies/features for now. But IMO we really should get back to it and replace it with our own implementation if we don't end up switching to tracing, for example.

Yes, this is exactly the plan, we can either switch to custom impl which supports rolling file logging or go for tracing.

If you feel strongly about this, I could do a quick follow up to have rolling file based logging with tracing dependencies, without using any of the other tracing features if that helps.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplelog doesn't work for us as an initial step.
Ldk server will be a long running process, hence i consider rolling file based logging a bare minimum for now.

IIUC the idea is to take the follow-up steps before this would ever run in production, no? Also, note that for making Server a good *IX citizen, we could at least consider actually integrating with syslog and logrotate rather than rolling our own?

Moreover, simplelog is also a single author crate

It's not? Github lists 38 contributors? That said, simplelog was merely an example of taking a simpler approach as a fill-in until we land on the actual logger.

If you feel strongly about this, I could do a quick follow up to have rolling file based logging with tracing dependencies, without using any of the other tracing features if that helps.

That would be great, although I have no strong opinion on the timeline, if we were to start out with a real simple fill-in logger. If you would prefer to roll with log4rs for now, I think we should make sure to actually get around to drop the dependencies further (in general btw), before releasing the 'official' 0.1.

Given how often security incidents related to malicious dependencies keep coming up, we should be very deliberate with what we take on. Btw. I'm considering whether to finally introduce features for LDK Node (likely with 0.6), which would at least allow us to compartmentalize the risk from (e.g, Server could avoid the dependency tree stemming from Electrum / Esplora backends, if it only requires bitcoind RPC support.

@G8XSU G8XSU marked this pull request as ready for review March 5, 2025 22:34
@G8XSU G8XSU requested a review from arik-so March 5, 2025 22:35
Copy link
Contributor

@arik-so arik-so left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given there doesn't appear to be a good alternative to log4rs, approving.

@tnull
Copy link
Collaborator

tnull commented Mar 8, 2025

Given there doesn't appear to be a good alternative to log4rs, approving.

That's not true. If you have a look at the linked LDK Node PR above, a bare-bones log-facade compatible logger can be implemented in sub 100 lines of code. And apart from that, there are several other 'simpler' log implementations around. Especially if we're considering this to be an initial step to be revisited soon, I don't know why we don't opt for the simplest implementation, that doesn't introduce a considerable dependency tree.

@@ -36,6 +36,8 @@ const USAGE_GUIDE: &str = "Usage: ldk-server <config_path>";
fn main() {
let args: Vec<String> = std::env::args().collect();

log4rs::init_file("./ldk-server/log4rs.toml", Default::default()).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems weird to hard-code this relative path in the binary. Do we expect to always start the server from the Git-workspace's directory, rather than the ldk-server directory, for example? Can we read this from the config at least?

@G8XSU G8XSU closed this Apr 15, 2025
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.

3 participants