Add configurable log level and log file#76
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.
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.
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.
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
| /// 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.
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.
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.
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.