-
Notifications
You must be signed in to change notification settings - Fork 21
Add configurable log level and log file #76
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
|
I've assigned @jkczyz as a reviewer! |
ldk-server/src/main.rs
Outdated
| .set_time_format_rfc3339() // set time format to rfc3339 (e.g. 2025-12-03T21:44:52.169154084Z) | ||
| .build(); | ||
| if let Err(e) = CombinedLogger::init(vec![ | ||
| SimpleLogger::new(config_file.log_level, log_config.clone()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't really clear from the docs as to why we need this. Does it got to stdout?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, added a comment
ldk-server/Cargo.toml
Outdated
| rand = { version = "0.8.5", default-features = false } | ||
| async-trait = { version = "0.1.85", default-features = false } | ||
| toml = { version = "0.8.9", default-features = false, features = ["parse"] } | ||
| simplelog = { version = "0.12.0", default-features = false } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than pulling in that depedency, can we just add a simple logger that implements the log facade? It's really trivial, for reference see the MockLogFacadeLogger in LDK Node tests: https://github.com/lightningdevkit/ldk-node/blob/198ff306bb70d1b6eb7bf9a4213716e22ae1db90/tests/common/logging.rs#L22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
| /// The minimum log level to display | ||
| level: LevelFilter, | ||
| /// The file to write logs to, buffered and protected by a mutex for thread-safe access | ||
| file: Mutex<BufWriter<File>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping the open file handle in a Mutex works, but then we should handle SIGHUP and make sure we drop and reopen the file handle to ensure compatibility with system tools such as logrotate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added handling for this, made things a little more complicated but nothing too bad
320676e to
b345b27
Compare
tnull
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically LGTM, just two minor comments.
Before we were dropping all our logs on the floor besides a few printlns in the code. This implements a logger for the log facade that writes logs to the console as well as to the log file. We also add to the config options for setting the log file and log level.
Before we were dropping all our logs on the floor besides a few printlns
in the code. This implements a logger for the log facade that writes
logs to the console as well as to the log file. We also add to the config
options for setting the log file and log level.