Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ logging to file, set `max_size_mb` and `rotation_interval_hours` params to `0`.
The server will also reopen the log file on `SIGHUP` for compatibility with external
tools like `logrotate`.

`level` and `file` are also available as `--log-level` / `LDK_SERVER_LOG_LEVEL` and
`--log-file` / `LDK_SERVER_LOG_FILE`.

### `[tls]`

TLS certificate and key paths, plus additional hostnames/IPs for the certificate's Subject
Expand Down
48 changes: 44 additions & 4 deletions ldk-server/src/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,14 @@ impl ConfigBuilder {
self.tor_proxy_address = Some(tor_proxy_address.clone());
}

if let Some(log_level) = &args.log_level {
self.log_level = Some(log_level.clone());
}

if let Some(log_file) = &args.log_file {
self.log_file_path = Some(log_file.clone());
}

if let Some(log_max_size_mb) = args.log_max_size_mb {
self.log_max_size_mb = Some(log_max_size_mb);
}
Expand Down Expand Up @@ -1205,6 +1213,20 @@ pub struct ArgsConfig {
)]
node_alias: Option<String>,

#[arg(
long,
env = "LDK_SERVER_LOG_LEVEL",
help = "The log level (Error, Warn, Info, Debug, Trace). Defaults to Debug."
)]
log_level: Option<String>,

#[arg(
long,
env = "LDK_SERVER_LOG_FILE",
help = "The path of the log file. Defaults to `ldk-server.log` in the network's storage directory."
)]
log_file: Option<String>,

#[arg(
long,
env = "LDK_SERVER_LOG_MAX_SIZE_MB",
Expand Down Expand Up @@ -1609,6 +1631,8 @@ mod tests {
metrics_username: None,
metrics_password: None,
tor_proxy_address: None,
log_level: Some(String::from("info")),
log_file: Some(String::from("/tmp_cli/ldk-server.log")),
log_to_file: Some(true),
log_max_size_mb: Some(50),
log_rotation_interval_hours: Some(24),
Expand Down Expand Up @@ -1652,6 +1676,8 @@ mod tests {
metrics_username: None,
metrics_password: None,
tor_proxy_address: None,
log_level: None,
log_file: None,
log_to_file: Some(true),
log_max_size_mb: None,
log_rotation_interval_hours: None,
Expand Down Expand Up @@ -2735,8 +2761,8 @@ mod tests {
rgs_server_url: None,
lsps_client_config: None,
lsps2_service_config: None,
log_level: LevelFilter::Trace,
log_file_path: Some("/var/log/ldk-server.log".to_string()),
log_level: LevelFilter::Info,
log_file_path: Some("/tmp_cli/ldk-server.log".to_string()),
pathfinding_scores_source_url: Some("https://example.com/".to_string()),
probing_config: None,
async_payments_role: Some(AsyncPaymentsRole::Server),
Expand Down Expand Up @@ -2781,6 +2807,8 @@ mod tests {
assert_eq!(config.log_rotation_interval_secs, expected.log_rotation_interval_secs);
assert_eq!(config.log_max_files, expected.log_max_files);
assert_eq!(config.log_to_file, expected.log_to_file);
assert_eq!(config.log_level, expected.log_level);
assert_eq!(config.log_file_path, expected.log_file_path);
}

#[test]
Expand Down Expand Up @@ -2872,8 +2900,8 @@ mod tests {
client_trusts_lsp: true,
disable_client_reserve: false,
}),
log_level: LevelFilter::Trace,
log_file_path: Some("/var/log/ldk-server.log".to_string()),
log_level: LevelFilter::Info,
log_file_path: Some("/tmp_cli/ldk-server.log".to_string()),
pathfinding_scores_source_url: Some("https://example.com/".to_string()),
probing_config: None,
async_payments_role: Some(AsyncPaymentsRole::Server),
Expand Down Expand Up @@ -2918,6 +2946,18 @@ mod tests {
);
assert_eq!(config.metrics_enabled, expected.metrics_enabled);
assert_eq!(config.tor_config, expected.tor_config);
assert_eq!(config.log_level, expected.log_level);
assert_eq!(config.log_file_path, expected.log_file_path);
}

#[test]
#[cfg(not(feature = "experimental-lsps2-support"))]
fn test_invalid_log_level_in_args_config() {
let mut args_config = default_args_config();
args_config.log_level = Some(String::from("verbose"));
let err = load_config(&args_config).unwrap_err();
assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
assert!(err.to_string().starts_with("Invalid log level configured"));
}

#[test]
Expand Down
Loading