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
8 changes: 8 additions & 0 deletions contrib/ldk-server-config.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,14 @@ dir_path = "/tmp/ldk-server/" # Path for LDK and BDK data persis
[log]
level = "Debug" # Log level (Error, Warn, Info, Debug, Trace)
#file = "/tmp/ldk-server/ldk-server.log" # Log file path
# Enabling `log_to_file` writes logs to the configured file while still keeping
# the `stdout`/`stderr` logs available too. Logs files are automatically rotated at # `max_size_mb` or `rotation_interval_hours`.
#
# To disable the internal rotation and keep logging to file, set `max_size_mb` # and `rotation_interval_hours` params to `0`.
log_to_file = true # Enable logging to a file (default: true, also logs to both stdout and stderr)
#max_size_mb = 50 # Max size of log file before rotation (default: 50MB)
#rotation_interval_hours = 24 # Max age of log file before rotation (default: 24h)
Comment thread
Anyitechs marked this conversation as resolved.
#max_files = 5 # Number of rotated log files to keep (default: 5)

[tls]
#cert_path = "/path/to/tls.crt" # Path to TLS certificate, by default uses dir_path/tls.crt
Expand Down
12 changes: 10 additions & 2 deletions docs/configuration.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,8 +61,16 @@ Where persistent data is stored. Defaults to `~/.ldk-server/` on Linux and

### `[log]`

Log level and file path. The server reopens the log file on `SIGHUP`, which integrates with
standard `logrotate` setups.
Controls logging behavior. By default, `log_to_file` is `true` and logs are also written
to `stdout`/`stderr`.

If `log_to_file` is enabled, logs are written to the configured file while still keeping
the `stdout`/`stderr` logs available too. Logs files are automatically rotated at
`max_size_mb` or `rotation_interval_hours`. To disable the internal rotation and keep
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`.

### `[tls]`

Expand Down
16 changes: 10 additions & 6 deletions docs/operations.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,13 +21,17 @@ The server handles `SIGTERM` and `CTRL-C` (SIGINT). On receipt, it:

### Log Rotation

> **Important:** LDK Server does not rotate or truncate its own log file. Without log rotation
> configured, the log file will grow indefinitely and can eventually fill your disk. A full
> disk can prevent the node from persisting channel state, risking fund loss.
By default, LDK Server logs to `stdout`/`stderr` and also to file. When running under `systemd` or Docker,
this allows the environment (e.g., `journald`) to handle persistence, rotation, and
compression automatically.

The server reopens its log file on `SIGHUP`. This integrates with standard `logrotate`. Save
the following config to `/etc/logrotate.d/ldk-server` (adjust the log path to match your
setup):
If you enable `log_to_file` in the configuration, LDK Server writes logs to the configured file while still
keeping the `stdout`/`stderr` logs available too. Logs files are automatically rotated at `max_size_mb` or `rotation_interval_hours`, and the last `max_files` uncompressed log files are retained. But you can disable
the internal rotation and keep logging to file by setting the `max_size_mb` and `rotation_interval_hours`
params to `0`.

If you prefer to use system `logrotate` for file logs, the server still reopens its log file on `SIGHUP`. Save
the following config to `/etc/logrotate.d/ldk-server` (adjust the log path to match your setup):

```
/var/lib/ldk-server/regtest/ldk-server.log {
Expand Down
35 changes: 24 additions & 11 deletions ldk-server/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,7 @@ use crate::io::persist::{
};
use crate::service::NodeService;
use crate::util::config::{load_config, ArgsConfig, ChainSource};
use crate::util::logger::ServerLogger;
use crate::util::logger::{LogConfig, ServerLogger};
use crate::util::metrics::Metrics;
use crate::util::proto_adapter::{forwarded_payment_to_proto, payment_to_proto};
use crate::util::systemd;
Expand DownExpand Up@@ -110,18 +110,29 @@ fn main() {
Network::Regtest => storage_dir.join("regtest"),
};

let log_file_path = config_file.log_file_path.map(PathBuf::from).unwrap_or_else(|| {
let mut default_log_path = network_dir.clone();
default_log_path.push("ldk-server.log");
default_log_path
});
let log_file_path = if config_file.log_to_file {
let path = config_file.log_file_path.map(PathBuf::from).unwrap_or_else(|| {
let mut default_log_path = network_dir.clone();
default_log_path.push("ldk-server.log");
default_log_path
});

if log_file_path == storage_dir || log_file_path == network_dir {
eprintln!("Log file path cannot be the same as storage directory path.");
std::process::exit(-1);
}
if path == storage_dir || path == network_dir {
eprintln!("Log file path cannot be the same as storage directory path.");
std::process::exit(-1);
}
Some(path)
} else {
None
};

let log_config = LogConfig {
log_max_files: config_file.log_max_files,
log_max_size_bytes: config_file.log_max_size_bytes,
log_rotation_interval_secs: config_file.log_rotation_interval_secs,
};

let logger = match ServerLogger::init(config_file.log_level, &log_file_path) {
let logger = match ServerLogger::init(config_file.log_level, log_file_path, log_config) {
Ok(logger) => logger,
Err(e) => {
eprintln!("Failed to initialize logger: {e}");
Expand DownExpand Up@@ -519,6 +530,7 @@ fn main() {
break;
}
_ = sighup_stream.recv() => {
info!("Received SIGHUP, reopening log file..");
if let Err(e) = logger.reopen() {
error!("Failed to reopen log file on SIGHUP: {e}");
}
Expand All@@ -535,6 +547,7 @@ fn main() {
systemd::notify_stopping();
node.stop().expect("Shutdown should always succeed.");
info!("Shutdown complete..");
log::logger().flush();
}

fn send_event_and_upsert_payment(
Expand Down
104 changes: 104 additions & 0 deletions ldk-server/src/util/config.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,9 @@ use log::LevelFilter;
use serde::{Deserialize, Serialize};

const DEFAULT_GRPC_SERVICE_ADDRESS: &str = "127.0.0.1:3536";
const DEFAULT_LOG_MAX_SIZE_MB: u64 = 50;
const DEFAULT_LOG_ROTATION_INTERVAL_HOURS: u64 = 24;
const DEFAULT_LOG_MAX_FILES: usize = 5;

#[cfg(not(test))]
const DEFAULT_CONFIG_FILE: &str = "config.toml";
Expand DownExpand Up@@ -56,6 +59,10 @@ pub struct Config {
pub lsps2_service_config: Option<LSPS2ServiceConfig>,
pub log_level: LevelFilter,
pub log_file_path: Option<String>,
pub log_max_size_bytes: usize,
pub log_rotation_interval_secs: u64,
pub log_max_files: usize,
pub log_to_file: bool,
pub pathfinding_scores_source_url: Option<String>,
pub metrics_enabled: bool,
pub poll_metrics_interval: Option<u64>,
Expand DownExpand Up@@ -110,6 +117,10 @@ struct ConfigBuilder {
lsps2: Option<LiquidityConfig>,
log_level: Option<String>,
log_file_path: Option<String>,
log_max_size_mb: Option<u64>,
log_rotation_interval_hours: Option<u64>,
log_max_files: Option<usize>,
log_to_file: Option<bool>,
pathfinding_scores_source_url: Option<String>,
metrics_enabled: Option<bool>,
poll_metrics_interval: Option<u64>,
Expand DownExpand Up@@ -158,6 +169,11 @@ impl ConfigBuilder {
if let Some(log) = toml.log {
self.log_level = log.level.or(self.log_level.clone());
self.log_file_path = log.file.or(self.log_file_path.clone());
self.log_max_size_mb = log.max_size_mb.or(self.log_max_size_mb);
self.log_rotation_interval_hours =
log.rotation_interval_hours.or(self.log_rotation_interval_hours);
self.log_max_files = log.max_files.or(self.log_max_files);
self.log_to_file = log.log_to_file.or(self.log_to_file);
}

if let Some(liquidity) = toml.liquidity {
Expand DownExpand Up@@ -249,6 +265,22 @@ impl ConfigBuilder {
if let Some(tor_proxy_address) = &args.tor_proxy_address {
self.tor_proxy_address = Some(tor_proxy_address.clone());
}

if let Some(log_max_size_mb) = args.log_max_size_mb {
self.log_max_size_mb = Some(log_max_size_mb);
}

if let Some(log_rotation_interval_hours) = args.log_rotation_interval_hours {
self.log_rotation_interval_hours = Some(log_rotation_interval_hours);
}

if let Some(log_max_files) = args.log_max_files {
self.log_max_files = Some(log_max_files);
}

if let Some(log_to_file) = args.log_to_file {
self.log_to_file = Some(log_to_file);
}
}

fn build(self) -> io::Result<Config> {
Expand DownExpand Up@@ -358,6 +390,14 @@ impl ConfigBuilder {
.transpose()?
.unwrap_or(LevelFilter::Debug);

let log_max_size_bytes =
self.log_max_size_mb.unwrap_or(DEFAULT_LOG_MAX_SIZE_MB) * 1024 * 1024;
let log_rotation_interval_secs =
self.log_rotation_interval_hours.unwrap_or(DEFAULT_LOG_ROTATION_INTERVAL_HOURS)
* 60 * 60;
let log_max_files = self.log_max_files.unwrap_or(DEFAULT_LOG_MAX_FILES);
let log_to_file = self.log_to_file.unwrap_or(true);

let lsps2_client_config = self
.lsps2
.as_ref()
Expand DownExpand Up@@ -428,6 +468,10 @@ impl ConfigBuilder {
lsps2_service_config,
log_level,
log_file_path: self.log_file_path,
log_max_size_bytes: log_max_size_bytes as usize,
log_rotation_interval_secs,
log_max_files,
log_to_file,
pathfinding_scores_source_url,
metrics_enabled,
poll_metrics_interval,
Expand DownExpand Up@@ -497,6 +541,10 @@ struct EsploraConfig {
struct LogConfig {
level: Option<String>,
file: Option<String>,
max_size_mb: Option<u64>,
rotation_interval_hours: Option<u64>,
max_files: Option<usize>,
log_to_file: Option<bool>,
}

#[derive(Deserialize, Serialize)]
Expand DownExpand Up@@ -733,6 +781,34 @@ pub struct ArgsConfig {
)]
node_alias: Option<String>,

#[arg(
long,
env = "LDK_SERVER_LOG_MAX_SIZE_MB",
help = "The maximum size of the log file in MB before rotation. Defaults to 50MB."
)]
log_max_size_mb: Option<u64>,

#[arg(
long,
env = "LDK_SERVER_LOG_ROTATION_INTERVAL_HOURS",
help = "The maximum age of the log file in hours before rotation. Defaults to 24h."
)]
log_rotation_interval_hours: Option<u64>,

#[arg(
long,
env = "LDK_SERVER_LOG_MAX_FILES",
help = "The maximum number of rotated log files to keep. Defaults to 5."
)]
log_max_files: Option<usize>,

#[arg(
long,
env = "LDK_SERVER_LOG_TO_FILE",
help = "The option to enable logging to a file. Defaults to true. If false, logging to file is disabled."
)]
log_to_file: Option<bool>,

#[arg(
long,
env = "LDK_SERVER_BITCOIND_RPC_ADDRESS",
Expand DownExpand Up@@ -896,6 +972,10 @@ mod tests {
[log]
level = "Trace"
file = "/var/log/ldk-server.log"
max_size_mb = 50
rotation_interval_hours = 24
max_files = 5
log_to_file = true

[bitcoind]
rpc_address = "127.0.0.1:8332"
Expand DownExpand Up@@ -941,6 +1021,10 @@ mod tests {
metrics_username: None,
metrics_password: None,
tor_proxy_address: None,
log_to_file: Some(true),
log_max_size_mb: Some(50),
log_rotation_interval_hours: Some(24),
log_max_files: Some(5),
}
}

Expand All@@ -962,6 +1046,10 @@ mod tests {
metrics_username: None,
metrics_password: None,
tor_proxy_address: None,
log_to_file: Some(true),
log_max_size_mb: None,
log_rotation_interval_hours: None,
log_max_files: None,
}
}

Expand DownExpand Up@@ -1029,6 +1117,10 @@ mod tests {
}),
log_level: LevelFilter::Trace,
log_file_path: Some("/var/log/ldk-server.log".to_string()),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: true,
pathfinding_scores_source_url: None,
metrics_enabled: false,
poll_metrics_interval: None,
Expand DownExpand Up@@ -1344,6 +1436,10 @@ mod tests {
metrics_password: None,
tor_config: None,
hrn_config: HumanReadableNamesConfig::default(),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: true,
};

assert_eq!(config.listening_addrs, expected.listening_addrs);
Expand All@@ -1357,6 +1453,10 @@ mod tests {
assert_eq!(config.pathfinding_scores_source_url, expected.pathfinding_scores_source_url);
assert_eq!(config.metrics_enabled, expected.metrics_enabled);
assert_eq!(config.tor_config, expected.tor_config);
assert_eq!(config.log_max_size_bytes, expected.log_max_size_bytes);
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);
}

#[test]
Expand DownExpand Up@@ -1454,6 +1554,10 @@ mod tests {
proxy_address: SocketAddress::from_str("127.0.0.1:9050").unwrap(),
}),
hrn_config: HumanReadableNamesConfig::default(),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: false,
};

assert_eq!(config.listening_addrs, expected.listening_addrs);
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
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
8 changes: 8 additions & 0 deletions contrib/ldk-server-config.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,14 @@ dir_path = "/tmp/ldk-server/" # Path for LDK and BDK data persis
[log]
level = "Debug" # Log level (Error, Warn, Info, Debug, Trace)
#file = "/tmp/ldk-server/ldk-server.log" # Log file path
# Enabling `log_to_file` writes logs to the configured file while still keeping
# the `stdout`/`stderr` logs available too. Logs files are automatically rotated at # `max_size_mb` or `rotation_interval_hours`.
#
# To disable the internal rotation and keep logging to file, set `max_size_mb` # and `rotation_interval_hours` params to `0`.
log_to_file = true # Enable logging to a file (default: true, also logs to both stdout and stderr)
#max_size_mb = 50 # Max size of log file before rotation (default: 50MB)
#rotation_interval_hours = 24 # Max age of log file before rotation (default: 24h)
Comment thread
Anyitechs marked this conversation as resolved.
#max_files = 5 # Number of rotated log files to keep (default: 5)

[tls]
#cert_path = "/path/to/tls.crt" # Path to TLS certificate, by default uses dir_path/tls.crt
Expand Down
12 changes: 10 additions & 2 deletions docs/configuration.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,8 +61,16 @@ Where persistent data is stored. Defaults to `~/.ldk-server/` on Linux and

### `[log]`

Log level and file path. The server reopens the log file on `SIGHUP`, which integrates with
standard `logrotate` setups.
Controls logging behavior. By default, `log_to_file` is `true` and logs are also written
to `stdout`/`stderr`.

If `log_to_file` is enabled, logs are written to the configured file while still keeping
the `stdout`/`stderr` logs available too. Logs files are automatically rotated at
`max_size_mb` or `rotation_interval_hours`. To disable the internal rotation and keep
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`.

### `[tls]`

Expand Down
16 changes: 10 additions & 6 deletions docs/operations.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,13 +21,17 @@ The server handles `SIGTERM` and `CTRL-C` (SIGINT). On receipt, it:

### Log Rotation

> **Important:** LDK Server does not rotate or truncate its own log file. Without log rotation
> configured, the log file will grow indefinitely and can eventually fill your disk. A full
> disk can prevent the node from persisting channel state, risking fund loss.
By default, LDK Server logs to `stdout`/`stderr` and also to file. When running under `systemd` or Docker,
this allows the environment (e.g., `journald`) to handle persistence, rotation, and
compression automatically.

The server reopens its log file on `SIGHUP`. This integrates with standard `logrotate`. Save
the following config to `/etc/logrotate.d/ldk-server` (adjust the log path to match your
setup):
If you enable `log_to_file` in the configuration, LDK Server writes logs to the configured file while still
keeping the `stdout`/`stderr` logs available too. Logs files are automatically rotated at `max_size_mb` or `rotation_interval_hours`, and the last `max_files` uncompressed log files are retained. But you can disable
the internal rotation and keep logging to file by setting the `max_size_mb` and `rotation_interval_hours`
params to `0`.

If you prefer to use system `logrotate` for file logs, the server still reopens its log file on `SIGHUP`. Save
the following config to `/etc/logrotate.d/ldk-server` (adjust the log path to match your setup):

```
/var/lib/ldk-server/regtest/ldk-server.log {
Expand Down
35 changes: 24 additions & 11 deletions ldk-server/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,7 @@ use crate::io::persist::{
};
use crate::service::NodeService;
use crate::util::config::{load_config, ArgsConfig, ChainSource};
use crate::util::logger::ServerLogger;
use crate::util::logger::{LogConfig, ServerLogger};
use crate::util::metrics::Metrics;
use crate::util::proto_adapter::{forwarded_payment_to_proto, payment_to_proto};
use crate::util::systemd;
Expand DownExpand Up@@ -110,18 +110,29 @@ fn main() {
Network::Regtest => storage_dir.join("regtest"),
};

let log_file_path = config_file.log_file_path.map(PathBuf::from).unwrap_or_else(|| {
let mut default_log_path = network_dir.clone();
default_log_path.push("ldk-server.log");
default_log_path
});
let log_file_path = if config_file.log_to_file {
let path = config_file.log_file_path.map(PathBuf::from).unwrap_or_else(|| {
let mut default_log_path = network_dir.clone();
default_log_path.push("ldk-server.log");
default_log_path
});

if log_file_path == storage_dir || log_file_path == network_dir {
eprintln!("Log file path cannot be the same as storage directory path.");
std::process::exit(-1);
}
if path == storage_dir || path == network_dir {
eprintln!("Log file path cannot be the same as storage directory path.");
std::process::exit(-1);
}
Some(path)
} else {
None
};

let log_config = LogConfig {
log_max_files: config_file.log_max_files,
log_max_size_bytes: config_file.log_max_size_bytes,
log_rotation_interval_secs: config_file.log_rotation_interval_secs,
};

let logger = match ServerLogger::init(config_file.log_level, &log_file_path) {
let logger = match ServerLogger::init(config_file.log_level, log_file_path, log_config) {
Ok(logger) => logger,
Err(e) => {
eprintln!("Failed to initialize logger: {e}");
Expand DownExpand Up@@ -519,6 +530,7 @@ fn main() {
break;
}
_ = sighup_stream.recv() => {
info!("Received SIGHUP, reopening log file..");
if let Err(e) = logger.reopen() {
error!("Failed to reopen log file on SIGHUP: {e}");
}
Expand All@@ -535,6 +547,7 @@ fn main() {
systemd::notify_stopping();
node.stop().expect("Shutdown should always succeed.");
info!("Shutdown complete..");
log::logger().flush();
}

fn send_event_and_upsert_payment(
Expand Down
104 changes: 104 additions & 0 deletions ldk-server/src/util/config.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,9 @@ use log::LevelFilter;
use serde::{Deserialize, Serialize};

const DEFAULT_GRPC_SERVICE_ADDRESS: &str = "127.0.0.1:3536";
const DEFAULT_LOG_MAX_SIZE_MB: u64 = 50;
const DEFAULT_LOG_ROTATION_INTERVAL_HOURS: u64 = 24;
const DEFAULT_LOG_MAX_FILES: usize = 5;

#[cfg(not(test))]
const DEFAULT_CONFIG_FILE: &str = "config.toml";
Expand DownExpand Up@@ -56,6 +59,10 @@ pub struct Config {
pub lsps2_service_config: Option<LSPS2ServiceConfig>,
pub log_level: LevelFilter,
pub log_file_path: Option<String>,
pub log_max_size_bytes: usize,
pub log_rotation_interval_secs: u64,
pub log_max_files: usize,
pub log_to_file: bool,
pub pathfinding_scores_source_url: Option<String>,
pub metrics_enabled: bool,
pub poll_metrics_interval: Option<u64>,
Expand DownExpand Up@@ -110,6 +117,10 @@ struct ConfigBuilder {
lsps2: Option<LiquidityConfig>,
log_level: Option<String>,
log_file_path: Option<String>,
log_max_size_mb: Option<u64>,
log_rotation_interval_hours: Option<u64>,
log_max_files: Option<usize>,
log_to_file: Option<bool>,
pathfinding_scores_source_url: Option<String>,
metrics_enabled: Option<bool>,
poll_metrics_interval: Option<u64>,
Expand DownExpand Up@@ -158,6 +169,11 @@ impl ConfigBuilder {
if let Some(log) = toml.log {
self.log_level = log.level.or(self.log_level.clone());
self.log_file_path = log.file.or(self.log_file_path.clone());
self.log_max_size_mb = log.max_size_mb.or(self.log_max_size_mb);
self.log_rotation_interval_hours =
log.rotation_interval_hours.or(self.log_rotation_interval_hours);
self.log_max_files = log.max_files.or(self.log_max_files);
self.log_to_file = log.log_to_file.or(self.log_to_file);
}

if let Some(liquidity) = toml.liquidity {
Expand DownExpand Up@@ -249,6 +265,22 @@ impl ConfigBuilder {
if let Some(tor_proxy_address) = &args.tor_proxy_address {
self.tor_proxy_address = Some(tor_proxy_address.clone());
}

if let Some(log_max_size_mb) = args.log_max_size_mb {
self.log_max_size_mb = Some(log_max_size_mb);
}

if let Some(log_rotation_interval_hours) = args.log_rotation_interval_hours {
self.log_rotation_interval_hours = Some(log_rotation_interval_hours);
}

if let Some(log_max_files) = args.log_max_files {
self.log_max_files = Some(log_max_files);
}

if let Some(log_to_file) = args.log_to_file {
self.log_to_file = Some(log_to_file);
}
}

fn build(self) -> io::Result<Config> {
Expand DownExpand Up@@ -358,6 +390,14 @@ impl ConfigBuilder {
.transpose()?
.unwrap_or(LevelFilter::Debug);

let log_max_size_bytes =
self.log_max_size_mb.unwrap_or(DEFAULT_LOG_MAX_SIZE_MB) * 1024 * 1024;
let log_rotation_interval_secs =
self.log_rotation_interval_hours.unwrap_or(DEFAULT_LOG_ROTATION_INTERVAL_HOURS)
* 60 * 60;
let log_max_files = self.log_max_files.unwrap_or(DEFAULT_LOG_MAX_FILES);
let log_to_file = self.log_to_file.unwrap_or(true);

let lsps2_client_config = self
.lsps2
.as_ref()
Expand DownExpand Up@@ -428,6 +468,10 @@ impl ConfigBuilder {
lsps2_service_config,
log_level,
log_file_path: self.log_file_path,
log_max_size_bytes: log_max_size_bytes as usize,
log_rotation_interval_secs,
log_max_files,
log_to_file,
pathfinding_scores_source_url,
metrics_enabled,
poll_metrics_interval,
Expand DownExpand Up@@ -497,6 +541,10 @@ struct EsploraConfig {
struct LogConfig {
level: Option<String>,
file: Option<String>,
max_size_mb: Option<u64>,
rotation_interval_hours: Option<u64>,
max_files: Option<usize>,
log_to_file: Option<bool>,
}

#[derive(Deserialize, Serialize)]
Expand DownExpand Up@@ -733,6 +781,34 @@ pub struct ArgsConfig {
)]
node_alias: Option<String>,

#[arg(
long,
env = "LDK_SERVER_LOG_MAX_SIZE_MB",
help = "The maximum size of the log file in MB before rotation. Defaults to 50MB."
)]
log_max_size_mb: Option<u64>,

#[arg(
long,
env = "LDK_SERVER_LOG_ROTATION_INTERVAL_HOURS",
help = "The maximum age of the log file in hours before rotation. Defaults to 24h."
)]
log_rotation_interval_hours: Option<u64>,

#[arg(
long,
env = "LDK_SERVER_LOG_MAX_FILES",
help = "The maximum number of rotated log files to keep. Defaults to 5."
)]
log_max_files: Option<usize>,

#[arg(
long,
env = "LDK_SERVER_LOG_TO_FILE",
help = "The option to enable logging to a file. Defaults to true. If false, logging to file is disabled."
)]
log_to_file: Option<bool>,

#[arg(
long,
env = "LDK_SERVER_BITCOIND_RPC_ADDRESS",
Expand DownExpand Up@@ -896,6 +972,10 @@ mod tests {
[log]
level = "Trace"
file = "/var/log/ldk-server.log"
max_size_mb = 50
rotation_interval_hours = 24
max_files = 5
log_to_file = true

[bitcoind]
rpc_address = "127.0.0.1:8332"
Expand DownExpand Up@@ -941,6 +1021,10 @@ mod tests {
metrics_username: None,
metrics_password: None,
tor_proxy_address: None,
log_to_file: Some(true),
log_max_size_mb: Some(50),
log_rotation_interval_hours: Some(24),
log_max_files: Some(5),
}
}

Expand All@@ -962,6 +1046,10 @@ mod tests {
metrics_username: None,
metrics_password: None,
tor_proxy_address: None,
log_to_file: Some(true),
log_max_size_mb: None,
log_rotation_interval_hours: None,
log_max_files: None,
}
}

Expand DownExpand Up@@ -1029,6 +1117,10 @@ mod tests {
}),
log_level: LevelFilter::Trace,
log_file_path: Some("/var/log/ldk-server.log".to_string()),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: true,
pathfinding_scores_source_url: None,
metrics_enabled: false,
poll_metrics_interval: None,
Expand DownExpand Up@@ -1344,6 +1436,10 @@ mod tests {
metrics_password: None,
tor_config: None,
hrn_config: HumanReadableNamesConfig::default(),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: true,
};

assert_eq!(config.listening_addrs, expected.listening_addrs);
Expand All@@ -1357,6 +1453,10 @@ mod tests {
assert_eq!(config.pathfinding_scores_source_url, expected.pathfinding_scores_source_url);
assert_eq!(config.metrics_enabled, expected.metrics_enabled);
assert_eq!(config.tor_config, expected.tor_config);
assert_eq!(config.log_max_size_bytes, expected.log_max_size_bytes);
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);
}

#[test]
Expand DownExpand Up@@ -1454,6 +1554,10 @@ mod tests {
proxy_address: SocketAddress::from_str("127.0.0.1:9050").unwrap(),
}),
hrn_config: HumanReadableNamesConfig::default(),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: false,
};

assert_eq!(config.listening_addrs, expected.listening_addrs);
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
8 changes: 8 additions & 0 deletions contrib/ldk-server-config.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,14 @@ dir_path = "/tmp/ldk-server/" # Path for LDK and BDK data persis
[log]
level = "Debug" # Log level (Error, Warn, Info, Debug, Trace)
#file = "/tmp/ldk-server/ldk-server.log" # Log file path
# Enabling `log_to_file` writes logs to the configured file while still keeping
# the `stdout`/`stderr` logs available too. Logs files are automatically rotated at # `max_size_mb` or `rotation_interval_hours`.
#
# To disable the internal rotation and keep logging to file, set `max_size_mb` # and `rotation_interval_hours` params to `0`.
log_to_file = true # Enable logging to a file (default: true, also logs to both stdout and stderr)
#max_size_mb = 50 # Max size of log file before rotation (default: 50MB)
#rotation_interval_hours = 24 # Max age of log file before rotation (default: 24h)
Comment thread
Anyitechs marked this conversation as resolved.
#max_files = 5 # Number of rotated log files to keep (default: 5)

[tls]
#cert_path = "/path/to/tls.crt" # Path to TLS certificate, by default uses dir_path/tls.crt
Expand Down
12 changes: 10 additions & 2 deletions docs/configuration.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,8 +61,16 @@ Where persistent data is stored. Defaults to `~/.ldk-server/` on Linux and

### `[log]`

Log level and file path. The server reopens the log file on `SIGHUP`, which integrates with
standard `logrotate` setups.
Controls logging behavior. By default, `log_to_file` is `true` and logs are also written
to `stdout`/`stderr`.

If `log_to_file` is enabled, logs are written to the configured file while still keeping
the `stdout`/`stderr` logs available too. Logs files are automatically rotated at
`max_size_mb` or `rotation_interval_hours`. To disable the internal rotation and keep
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`.

### `[tls]`

Expand Down
16 changes: 10 additions & 6 deletions docs/operations.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,13 +21,17 @@ The server handles `SIGTERM` and `CTRL-C` (SIGINT). On receipt, it:

### Log Rotation

> **Important:** LDK Server does not rotate or truncate its own log file. Without log rotation
> configured, the log file will grow indefinitely and can eventually fill your disk. A full
> disk can prevent the node from persisting channel state, risking fund loss.
By default, LDK Server logs to `stdout`/`stderr` and also to file. When running under `systemd` or Docker,
this allows the environment (e.g., `journald`) to handle persistence, rotation, and
compression automatically.

The server reopens its log file on `SIGHUP`. This integrates with standard `logrotate`. Save
the following config to `/etc/logrotate.d/ldk-server` (adjust the log path to match your
setup):
If you enable `log_to_file` in the configuration, LDK Server writes logs to the configured file while still
keeping the `stdout`/`stderr` logs available too. Logs files are automatically rotated at `max_size_mb` or `rotation_interval_hours`, and the last `max_files` uncompressed log files are retained. But you can disable
the internal rotation and keep logging to file by setting the `max_size_mb` and `rotation_interval_hours`
params to `0`.

If you prefer to use system `logrotate` for file logs, the server still reopens its log file on `SIGHUP`. Save
the following config to `/etc/logrotate.d/ldk-server` (adjust the log path to match your setup):

```
/var/lib/ldk-server/regtest/ldk-server.log {
Expand Down
35 changes: 24 additions & 11 deletions ldk-server/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,7 @@ use crate::io::persist::{
};
use crate::service::NodeService;
use crate::util::config::{load_config, ArgsConfig, ChainSource};
use crate::util::logger::ServerLogger;
use crate::util::logger::{LogConfig, ServerLogger};
use crate::util::metrics::Metrics;
use crate::util::proto_adapter::{forwarded_payment_to_proto, payment_to_proto};
use crate::util::systemd;
Expand DownExpand Up@@ -110,18 +110,29 @@ fn main() {
Network::Regtest => storage_dir.join("regtest"),
};

let log_file_path = config_file.log_file_path.map(PathBuf::from).unwrap_or_else(|| {
let mut default_log_path = network_dir.clone();
default_log_path.push("ldk-server.log");
default_log_path
});
let log_file_path = if config_file.log_to_file {
let path = config_file.log_file_path.map(PathBuf::from).unwrap_or_else(|| {
let mut default_log_path = network_dir.clone();
default_log_path.push("ldk-server.log");
default_log_path
});

if log_file_path == storage_dir || log_file_path == network_dir {
eprintln!("Log file path cannot be the same as storage directory path.");
std::process::exit(-1);
}
if path == storage_dir || path == network_dir {
eprintln!("Log file path cannot be the same as storage directory path.");
std::process::exit(-1);
}
Some(path)
} else {
None
};

let log_config = LogConfig {
log_max_files: config_file.log_max_files,
log_max_size_bytes: config_file.log_max_size_bytes,
log_rotation_interval_secs: config_file.log_rotation_interval_secs,
};

let logger = match ServerLogger::init(config_file.log_level, &log_file_path) {
let logger = match ServerLogger::init(config_file.log_level, log_file_path, log_config) {
Ok(logger) => logger,
Err(e) => {
eprintln!("Failed to initialize logger: {e}");
Expand DownExpand Up@@ -519,6 +530,7 @@ fn main() {
break;
}
_ = sighup_stream.recv() => {
info!("Received SIGHUP, reopening log file..");
if let Err(e) = logger.reopen() {
error!("Failed to reopen log file on SIGHUP: {e}");
}
Expand All@@ -535,6 +547,7 @@ fn main() {
systemd::notify_stopping();
node.stop().expect("Shutdown should always succeed.");
info!("Shutdown complete..");
log::logger().flush();
}

fn send_event_and_upsert_payment(
Expand Down
104 changes: 104 additions & 0 deletions ldk-server/src/util/config.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,9 @@ use log::LevelFilter;
use serde::{Deserialize, Serialize};

const DEFAULT_GRPC_SERVICE_ADDRESS: &str = "127.0.0.1:3536";
const DEFAULT_LOG_MAX_SIZE_MB: u64 = 50;
const DEFAULT_LOG_ROTATION_INTERVAL_HOURS: u64 = 24;
const DEFAULT_LOG_MAX_FILES: usize = 5;

#[cfg(not(test))]
const DEFAULT_CONFIG_FILE: &str = "config.toml";
Expand DownExpand Up@@ -56,6 +59,10 @@ pub struct Config {
pub lsps2_service_config: Option<LSPS2ServiceConfig>,
pub log_level: LevelFilter,
pub log_file_path: Option<String>,
pub log_max_size_bytes: usize,
pub log_rotation_interval_secs: u64,
pub log_max_files: usize,
pub log_to_file: bool,
pub pathfinding_scores_source_url: Option<String>,
pub metrics_enabled: bool,
pub poll_metrics_interval: Option<u64>,
Expand DownExpand Up@@ -110,6 +117,10 @@ struct ConfigBuilder {
lsps2: Option<LiquidityConfig>,
log_level: Option<String>,
log_file_path: Option<String>,
log_max_size_mb: Option<u64>,
log_rotation_interval_hours: Option<u64>,
log_max_files: Option<usize>,
log_to_file: Option<bool>,
pathfinding_scores_source_url: Option<String>,
metrics_enabled: Option<bool>,
poll_metrics_interval: Option<u64>,
Expand DownExpand Up@@ -158,6 +169,11 @@ impl ConfigBuilder {
if let Some(log) = toml.log {
self.log_level = log.level.or(self.log_level.clone());
self.log_file_path = log.file.or(self.log_file_path.clone());
self.log_max_size_mb = log.max_size_mb.or(self.log_max_size_mb);
self.log_rotation_interval_hours =
log.rotation_interval_hours.or(self.log_rotation_interval_hours);
self.log_max_files = log.max_files.or(self.log_max_files);
self.log_to_file = log.log_to_file.or(self.log_to_file);
}

if let Some(liquidity) = toml.liquidity {
Expand DownExpand Up@@ -249,6 +265,22 @@ impl ConfigBuilder {
if let Some(tor_proxy_address) = &args.tor_proxy_address {
self.tor_proxy_address = Some(tor_proxy_address.clone());
}

if let Some(log_max_size_mb) = args.log_max_size_mb {
self.log_max_size_mb = Some(log_max_size_mb);
}

if let Some(log_rotation_interval_hours) = args.log_rotation_interval_hours {
self.log_rotation_interval_hours = Some(log_rotation_interval_hours);
}

if let Some(log_max_files) = args.log_max_files {
self.log_max_files = Some(log_max_files);
}

if let Some(log_to_file) = args.log_to_file {
self.log_to_file = Some(log_to_file);
}
}

fn build(self) -> io::Result<Config> {
Expand DownExpand Up@@ -358,6 +390,14 @@ impl ConfigBuilder {
.transpose()?
.unwrap_or(LevelFilter::Debug);

let log_max_size_bytes =
self.log_max_size_mb.unwrap_or(DEFAULT_LOG_MAX_SIZE_MB) * 1024 * 1024;
let log_rotation_interval_secs =
self.log_rotation_interval_hours.unwrap_or(DEFAULT_LOG_ROTATION_INTERVAL_HOURS)
* 60 * 60;
let log_max_files = self.log_max_files.unwrap_or(DEFAULT_LOG_MAX_FILES);
let log_to_file = self.log_to_file.unwrap_or(true);

let lsps2_client_config = self
.lsps2
.as_ref()
Expand DownExpand Up@@ -428,6 +468,10 @@ impl ConfigBuilder {
lsps2_service_config,
log_level,
log_file_path: self.log_file_path,
log_max_size_bytes: log_max_size_bytes as usize,
log_rotation_interval_secs,
log_max_files,
log_to_file,
pathfinding_scores_source_url,
metrics_enabled,
poll_metrics_interval,
Expand DownExpand Up@@ -497,6 +541,10 @@ struct EsploraConfig {
struct LogConfig {
level: Option<String>,
file: Option<String>,
max_size_mb: Option<u64>,
rotation_interval_hours: Option<u64>,
max_files: Option<usize>,
log_to_file: Option<bool>,
}

#[derive(Deserialize, Serialize)]
Expand DownExpand Up@@ -733,6 +781,34 @@ pub struct ArgsConfig {
)]
node_alias: Option<String>,

#[arg(
long,
env = "LDK_SERVER_LOG_MAX_SIZE_MB",
help = "The maximum size of the log file in MB before rotation. Defaults to 50MB."
)]
log_max_size_mb: Option<u64>,

#[arg(
long,
env = "LDK_SERVER_LOG_ROTATION_INTERVAL_HOURS",
help = "The maximum age of the log file in hours before rotation. Defaults to 24h."
)]
log_rotation_interval_hours: Option<u64>,

#[arg(
long,
env = "LDK_SERVER_LOG_MAX_FILES",
help = "The maximum number of rotated log files to keep. Defaults to 5."
)]
log_max_files: Option<usize>,

#[arg(
long,
env = "LDK_SERVER_LOG_TO_FILE",
help = "The option to enable logging to a file. Defaults to true. If false, logging to file is disabled."
)]
log_to_file: Option<bool>,

#[arg(
long,
env = "LDK_SERVER_BITCOIND_RPC_ADDRESS",
Expand DownExpand Up@@ -896,6 +972,10 @@ mod tests {
[log]
level = "Trace"
file = "/var/log/ldk-server.log"
max_size_mb = 50
rotation_interval_hours = 24
max_files = 5
log_to_file = true

[bitcoind]
rpc_address = "127.0.0.1:8332"
Expand DownExpand Up@@ -941,6 +1021,10 @@ mod tests {
metrics_username: None,
metrics_password: None,
tor_proxy_address: None,
log_to_file: Some(true),
log_max_size_mb: Some(50),
log_rotation_interval_hours: Some(24),
log_max_files: Some(5),
}
}

Expand All@@ -962,6 +1046,10 @@ mod tests {
metrics_username: None,
metrics_password: None,
tor_proxy_address: None,
log_to_file: Some(true),
log_max_size_mb: None,
log_rotation_interval_hours: None,
log_max_files: None,
}
}

Expand DownExpand Up@@ -1029,6 +1117,10 @@ mod tests {
}),
log_level: LevelFilter::Trace,
log_file_path: Some("/var/log/ldk-server.log".to_string()),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: true,
pathfinding_scores_source_url: None,
metrics_enabled: false,
poll_metrics_interval: None,
Expand DownExpand Up@@ -1344,6 +1436,10 @@ mod tests {
metrics_password: None,
tor_config: None,
hrn_config: HumanReadableNamesConfig::default(),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: true,
};

assert_eq!(config.listening_addrs, expected.listening_addrs);
Expand All@@ -1357,6 +1453,10 @@ mod tests {
assert_eq!(config.pathfinding_scores_source_url, expected.pathfinding_scores_source_url);
assert_eq!(config.metrics_enabled, expected.metrics_enabled);
assert_eq!(config.tor_config, expected.tor_config);
assert_eq!(config.log_max_size_bytes, expected.log_max_size_bytes);
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);
}

#[test]
Expand DownExpand Up@@ -1454,6 +1554,10 @@ mod tests {
proxy_address: SocketAddress::from_str("127.0.0.1:9050").unwrap(),
}),
hrn_config: HumanReadableNamesConfig::default(),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: false,
};

assert_eq!(config.listening_addrs, expected.listening_addrs);
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
8 changes: 8 additions & 0 deletions contrib/ldk-server-config.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,14 @@ dir_path = "/tmp/ldk-server/" # Path for LDK and BDK data persis
[log]
level = "Debug" # Log level (Error, Warn, Info, Debug, Trace)
#file = "/tmp/ldk-server/ldk-server.log" # Log file path
# Enabling `log_to_file` writes logs to the configured file while still keeping
# the `stdout`/`stderr` logs available too. Logs files are automatically rotated at # `max_size_mb` or `rotation_interval_hours`.
#
# To disable the internal rotation and keep logging to file, set `max_size_mb` # and `rotation_interval_hours` params to `0`.
log_to_file = true # Enable logging to a file (default: true, also logs to both stdout and stderr)
#max_size_mb = 50 # Max size of log file before rotation (default: 50MB)
#rotation_interval_hours = 24 # Max age of log file before rotation (default: 24h)
Comment thread
Anyitechs marked this conversation as resolved.
#max_files = 5 # Number of rotated log files to keep (default: 5)

[tls]
#cert_path = "/path/to/tls.crt" # Path to TLS certificate, by default uses dir_path/tls.crt
Expand Down
12 changes: 10 additions & 2 deletions docs/configuration.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,8 +61,16 @@ Where persistent data is stored. Defaults to `~/.ldk-server/` on Linux and

### `[log]`

Log level and file path. The server reopens the log file on `SIGHUP`, which integrates with
standard `logrotate` setups.
Controls logging behavior. By default, `log_to_file` is `true` and logs are also written
to `stdout`/`stderr`.

If `log_to_file` is enabled, logs are written to the configured file while still keeping
the `stdout`/`stderr` logs available too. Logs files are automatically rotated at
`max_size_mb` or `rotation_interval_hours`. To disable the internal rotation and keep
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`.

### `[tls]`

Expand Down
16 changes: 10 additions & 6 deletions docs/operations.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,13 +21,17 @@ The server handles `SIGTERM` and `CTRL-C` (SIGINT). On receipt, it:

### Log Rotation

> **Important:** LDK Server does not rotate or truncate its own log file. Without log rotation
> configured, the log file will grow indefinitely and can eventually fill your disk. A full
> disk can prevent the node from persisting channel state, risking fund loss.
By default, LDK Server logs to `stdout`/`stderr` and also to file. When running under `systemd` or Docker,
this allows the environment (e.g., `journald`) to handle persistence, rotation, and
compression automatically.

The server reopens its log file on `SIGHUP`. This integrates with standard `logrotate`. Save
the following config to `/etc/logrotate.d/ldk-server` (adjust the log path to match your
setup):
If you enable `log_to_file` in the configuration, LDK Server writes logs to the configured file while still
keeping the `stdout`/`stderr` logs available too. Logs files are automatically rotated at `max_size_mb` or `rotation_interval_hours`, and the last `max_files` uncompressed log files are retained. But you can disable
the internal rotation and keep logging to file by setting the `max_size_mb` and `rotation_interval_hours`
params to `0`.

If you prefer to use system `logrotate` for file logs, the server still reopens its log file on `SIGHUP`. Save
the following config to `/etc/logrotate.d/ldk-server` (adjust the log path to match your setup):

```
/var/lib/ldk-server/regtest/ldk-server.log {
Expand Down
35 changes: 24 additions & 11 deletions ldk-server/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,7 @@ use crate::io::persist::{
};
use crate::service::NodeService;
use crate::util::config::{load_config, ArgsConfig, ChainSource};
use crate::util::logger::ServerLogger;
use crate::util::logger::{LogConfig, ServerLogger};
use crate::util::metrics::Metrics;
use crate::util::proto_adapter::{forwarded_payment_to_proto, payment_to_proto};
use crate::util::systemd;
Expand DownExpand Up@@ -110,18 +110,29 @@ fn main() {
Network::Regtest => storage_dir.join("regtest"),
};

let log_file_path = config_file.log_file_path.map(PathBuf::from).unwrap_or_else(|| {
let mut default_log_path = network_dir.clone();
default_log_path.push("ldk-server.log");
default_log_path
});
let log_file_path = if config_file.log_to_file {
let path = config_file.log_file_path.map(PathBuf::from).unwrap_or_else(|| {
let mut default_log_path = network_dir.clone();
default_log_path.push("ldk-server.log");
default_log_path
});

if log_file_path == storage_dir || log_file_path == network_dir {
eprintln!("Log file path cannot be the same as storage directory path.");
std::process::exit(-1);
}
if path == storage_dir || path == network_dir {
eprintln!("Log file path cannot be the same as storage directory path.");
std::process::exit(-1);
}
Some(path)
} else {
None
};

let log_config = LogConfig {
log_max_files: config_file.log_max_files,
log_max_size_bytes: config_file.log_max_size_bytes,
log_rotation_interval_secs: config_file.log_rotation_interval_secs,
};

let logger = match ServerLogger::init(config_file.log_level, &log_file_path) {
let logger = match ServerLogger::init(config_file.log_level, log_file_path, log_config) {
Ok(logger) => logger,
Err(e) => {
eprintln!("Failed to initialize logger: {e}");
Expand DownExpand Up@@ -519,6 +530,7 @@ fn main() {
break;
}
_ = sighup_stream.recv() => {
info!("Received SIGHUP, reopening log file..");
if let Err(e) = logger.reopen() {
error!("Failed to reopen log file on SIGHUP: {e}");
}
Expand All@@ -535,6 +547,7 @@ fn main() {
systemd::notify_stopping();
node.stop().expect("Shutdown should always succeed.");
info!("Shutdown complete..");
log::logger().flush();
}

fn send_event_and_upsert_payment(
Expand Down
104 changes: 104 additions & 0 deletions ldk-server/src/util/config.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,9 @@ use log::LevelFilter;
use serde::{Deserialize, Serialize};

const DEFAULT_GRPC_SERVICE_ADDRESS: &str = "127.0.0.1:3536";
const DEFAULT_LOG_MAX_SIZE_MB: u64 = 50;
const DEFAULT_LOG_ROTATION_INTERVAL_HOURS: u64 = 24;
const DEFAULT_LOG_MAX_FILES: usize = 5;

#[cfg(not(test))]
const DEFAULT_CONFIG_FILE: &str = "config.toml";
Expand DownExpand Up@@ -56,6 +59,10 @@ pub struct Config {
pub lsps2_service_config: Option<LSPS2ServiceConfig>,
pub log_level: LevelFilter,
pub log_file_path: Option<String>,
pub log_max_size_bytes: usize,
pub log_rotation_interval_secs: u64,
pub log_max_files: usize,
pub log_to_file: bool,
pub pathfinding_scores_source_url: Option<String>,
pub metrics_enabled: bool,
pub poll_metrics_interval: Option<u64>,
Expand DownExpand Up@@ -110,6 +117,10 @@ struct ConfigBuilder {
lsps2: Option<LiquidityConfig>,
log_level: Option<String>,
log_file_path: Option<String>,
log_max_size_mb: Option<u64>,
log_rotation_interval_hours: Option<u64>,
log_max_files: Option<usize>,
log_to_file: Option<bool>,
pathfinding_scores_source_url: Option<String>,
metrics_enabled: Option<bool>,
poll_metrics_interval: Option<u64>,
Expand DownExpand Up@@ -158,6 +169,11 @@ impl ConfigBuilder {
if let Some(log) = toml.log {
self.log_level = log.level.or(self.log_level.clone());
self.log_file_path = log.file.or(self.log_file_path.clone());
self.log_max_size_mb = log.max_size_mb.or(self.log_max_size_mb);
self.log_rotation_interval_hours =
log.rotation_interval_hours.or(self.log_rotation_interval_hours);
self.log_max_files = log.max_files.or(self.log_max_files);
self.log_to_file = log.log_to_file.or(self.log_to_file);
}

if let Some(liquidity) = toml.liquidity {
Expand DownExpand Up@@ -249,6 +265,22 @@ impl ConfigBuilder {
if let Some(tor_proxy_address) = &args.tor_proxy_address {
self.tor_proxy_address = Some(tor_proxy_address.clone());
}

if let Some(log_max_size_mb) = args.log_max_size_mb {
self.log_max_size_mb = Some(log_max_size_mb);
}

if let Some(log_rotation_interval_hours) = args.log_rotation_interval_hours {
self.log_rotation_interval_hours = Some(log_rotation_interval_hours);
}

if let Some(log_max_files) = args.log_max_files {
self.log_max_files = Some(log_max_files);
}

if let Some(log_to_file) = args.log_to_file {
self.log_to_file = Some(log_to_file);
}
}

fn build(self) -> io::Result<Config> {
Expand DownExpand Up@@ -358,6 +390,14 @@ impl ConfigBuilder {
.transpose()?
.unwrap_or(LevelFilter::Debug);

let log_max_size_bytes =
self.log_max_size_mb.unwrap_or(DEFAULT_LOG_MAX_SIZE_MB) * 1024 * 1024;
let log_rotation_interval_secs =
self.log_rotation_interval_hours.unwrap_or(DEFAULT_LOG_ROTATION_INTERVAL_HOURS)
* 60 * 60;
let log_max_files = self.log_max_files.unwrap_or(DEFAULT_LOG_MAX_FILES);
let log_to_file = self.log_to_file.unwrap_or(true);

let lsps2_client_config = self
.lsps2
.as_ref()
Expand DownExpand Up@@ -428,6 +468,10 @@ impl ConfigBuilder {
lsps2_service_config,
log_level,
log_file_path: self.log_file_path,
log_max_size_bytes: log_max_size_bytes as usize,
log_rotation_interval_secs,
log_max_files,
log_to_file,
pathfinding_scores_source_url,
metrics_enabled,
poll_metrics_interval,
Expand DownExpand Up@@ -497,6 +541,10 @@ struct EsploraConfig {
struct LogConfig {
level: Option<String>,
file: Option<String>,
max_size_mb: Option<u64>,
rotation_interval_hours: Option<u64>,
max_files: Option<usize>,
log_to_file: Option<bool>,
}

#[derive(Deserialize, Serialize)]
Expand DownExpand Up@@ -733,6 +781,34 @@ pub struct ArgsConfig {
)]
node_alias: Option<String>,

#[arg(
long,
env = "LDK_SERVER_LOG_MAX_SIZE_MB",
help = "The maximum size of the log file in MB before rotation. Defaults to 50MB."
)]
log_max_size_mb: Option<u64>,

#[arg(
long,
env = "LDK_SERVER_LOG_ROTATION_INTERVAL_HOURS",
help = "The maximum age of the log file in hours before rotation. Defaults to 24h."
)]
log_rotation_interval_hours: Option<u64>,

#[arg(
long,
env = "LDK_SERVER_LOG_MAX_FILES",
help = "The maximum number of rotated log files to keep. Defaults to 5."
)]
log_max_files: Option<usize>,

#[arg(
long,
env = "LDK_SERVER_LOG_TO_FILE",
help = "The option to enable logging to a file. Defaults to true. If false, logging to file is disabled."
)]
log_to_file: Option<bool>,

#[arg(
long,
env = "LDK_SERVER_BITCOIND_RPC_ADDRESS",
Expand DownExpand Up@@ -896,6 +972,10 @@ mod tests {
[log]
level = "Trace"
file = "/var/log/ldk-server.log"
max_size_mb = 50
rotation_interval_hours = 24
max_files = 5
log_to_file = true

[bitcoind]
rpc_address = "127.0.0.1:8332"
Expand DownExpand Up@@ -941,6 +1021,10 @@ mod tests {
metrics_username: None,
metrics_password: None,
tor_proxy_address: None,
log_to_file: Some(true),
log_max_size_mb: Some(50),
log_rotation_interval_hours: Some(24),
log_max_files: Some(5),
}
}

Expand All@@ -962,6 +1046,10 @@ mod tests {
metrics_username: None,
metrics_password: None,
tor_proxy_address: None,
log_to_file: Some(true),
log_max_size_mb: None,
log_rotation_interval_hours: None,
log_max_files: None,
}
}

Expand DownExpand Up@@ -1029,6 +1117,10 @@ mod tests {
}),
log_level: LevelFilter::Trace,
log_file_path: Some("/var/log/ldk-server.log".to_string()),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: true,
pathfinding_scores_source_url: None,
metrics_enabled: false,
poll_metrics_interval: None,
Expand DownExpand Up@@ -1344,6 +1436,10 @@ mod tests {
metrics_password: None,
tor_config: None,
hrn_config: HumanReadableNamesConfig::default(),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: true,
};

assert_eq!(config.listening_addrs, expected.listening_addrs);
Expand All@@ -1357,6 +1453,10 @@ mod tests {
assert_eq!(config.pathfinding_scores_source_url, expected.pathfinding_scores_source_url);
assert_eq!(config.metrics_enabled, expected.metrics_enabled);
assert_eq!(config.tor_config, expected.tor_config);
assert_eq!(config.log_max_size_bytes, expected.log_max_size_bytes);
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);
}

#[test]
Expand DownExpand Up@@ -1454,6 +1554,10 @@ mod tests {
proxy_address: SocketAddress::from_str("127.0.0.1:9050").unwrap(),
}),
hrn_config: HumanReadableNamesConfig::default(),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: false,
};

assert_eq!(config.listening_addrs, expected.listening_addrs);
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
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
8 changes: 8 additions & 0 deletions contrib/ldk-server-config.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,14 @@ dir_path = "/tmp/ldk-server/" # Path for LDK and BDK data persis
[log]
level = "Debug" # Log level (Error, Warn, Info, Debug, Trace)
#file = "/tmp/ldk-server/ldk-server.log" # Log file path
# Enabling `log_to_file` writes logs to the configured file while still keeping
# the `stdout`/`stderr` logs available too. Logs files are automatically rotated at # `max_size_mb` or `rotation_interval_hours`.
#
# To disable the internal rotation and keep logging to file, set `max_size_mb` # and `rotation_interval_hours` params to `0`.
log_to_file = true # Enable logging to a file (default: true, also logs to both stdout and stderr)
#max_size_mb = 50 # Max size of log file before rotation (default: 50MB)
#rotation_interval_hours = 24 # Max age of log file before rotation (default: 24h)
Comment thread
Anyitechs marked this conversation as resolved.
#max_files = 5 # Number of rotated log files to keep (default: 5)

[tls]
#cert_path = "/path/to/tls.crt" # Path to TLS certificate, by default uses dir_path/tls.crt
Expand Down
12 changes: 10 additions & 2 deletions docs/configuration.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,8 +61,16 @@ Where persistent data is stored. Defaults to `~/.ldk-server/` on Linux and

### `[log]`

Log level and file path. The server reopens the log file on `SIGHUP`, which integrates with
standard `logrotate` setups.
Controls logging behavior. By default, `log_to_file` is `true` and logs are also written
to `stdout`/`stderr`.

If `log_to_file` is enabled, logs are written to the configured file while still keeping
the `stdout`/`stderr` logs available too. Logs files are automatically rotated at
`max_size_mb` or `rotation_interval_hours`. To disable the internal rotation and keep
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`.

### `[tls]`

Expand Down
16 changes: 10 additions & 6 deletions docs/operations.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,13 +21,17 @@ The server handles `SIGTERM` and `CTRL-C` (SIGINT). On receipt, it:

### Log Rotation

> **Important:** LDK Server does not rotate or truncate its own log file. Without log rotation
> configured, the log file will grow indefinitely and can eventually fill your disk. A full
> disk can prevent the node from persisting channel state, risking fund loss.
By default, LDK Server logs to `stdout`/`stderr` and also to file. When running under `systemd` or Docker,
this allows the environment (e.g., `journald`) to handle persistence, rotation, and
compression automatically.

The server reopens its log file on `SIGHUP`. This integrates with standard `logrotate`. Save
the following config to `/etc/logrotate.d/ldk-server` (adjust the log path to match your
setup):
If you enable `log_to_file` in the configuration, LDK Server writes logs to the configured file while still
keeping the `stdout`/`stderr` logs available too. Logs files are automatically rotated at `max_size_mb` or `rotation_interval_hours`, and the last `max_files` uncompressed log files are retained. But you can disable
the internal rotation and keep logging to file by setting the `max_size_mb` and `rotation_interval_hours`
params to `0`.

If you prefer to use system `logrotate` for file logs, the server still reopens its log file on `SIGHUP`. Save
the following config to `/etc/logrotate.d/ldk-server` (adjust the log path to match your setup):

```
/var/lib/ldk-server/regtest/ldk-server.log {
Expand Down
35 changes: 24 additions & 11 deletions ldk-server/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,7 @@ use crate::io::persist::{
};
use crate::service::NodeService;
use crate::util::config::{load_config, ArgsConfig, ChainSource};
use crate::util::logger::ServerLogger;
use crate::util::logger::{LogConfig, ServerLogger};
use crate::util::metrics::Metrics;
use crate::util::proto_adapter::{forwarded_payment_to_proto, payment_to_proto};
use crate::util::systemd;
Expand DownExpand Up@@ -110,18 +110,29 @@ fn main() {
Network::Regtest => storage_dir.join("regtest"),
};

let log_file_path = config_file.log_file_path.map(PathBuf::from).unwrap_or_else(|| {
let mut default_log_path = network_dir.clone();
default_log_path.push("ldk-server.log");
default_log_path
});
let log_file_path = if config_file.log_to_file {
let path = config_file.log_file_path.map(PathBuf::from).unwrap_or_else(|| {
let mut default_log_path = network_dir.clone();
default_log_path.push("ldk-server.log");
default_log_path
});

if log_file_path == storage_dir || log_file_path == network_dir {
eprintln!("Log file path cannot be the same as storage directory path.");
std::process::exit(-1);
}
if path == storage_dir || path == network_dir {
eprintln!("Log file path cannot be the same as storage directory path.");
std::process::exit(-1);
}
Some(path)
} else {
None
};

let log_config = LogConfig {
log_max_files: config_file.log_max_files,
log_max_size_bytes: config_file.log_max_size_bytes,
log_rotation_interval_secs: config_file.log_rotation_interval_secs,
};

let logger = match ServerLogger::init(config_file.log_level, &log_file_path) {
let logger = match ServerLogger::init(config_file.log_level, log_file_path, log_config) {
Ok(logger) => logger,
Err(e) => {
eprintln!("Failed to initialize logger: {e}");
Expand DownExpand Up@@ -519,6 +530,7 @@ fn main() {
break;
}
_ = sighup_stream.recv() => {
info!("Received SIGHUP, reopening log file..");
if let Err(e) = logger.reopen() {
error!("Failed to reopen log file on SIGHUP: {e}");
}
Expand All@@ -535,6 +547,7 @@ fn main() {
systemd::notify_stopping();
node.stop().expect("Shutdown should always succeed.");
info!("Shutdown complete..");
log::logger().flush();
}

fn send_event_and_upsert_payment(
Expand Down
104 changes: 104 additions & 0 deletions ldk-server/src/util/config.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,9 @@ use log::LevelFilter;
use serde::{Deserialize, Serialize};

const DEFAULT_GRPC_SERVICE_ADDRESS: &str = "127.0.0.1:3536";
const DEFAULT_LOG_MAX_SIZE_MB: u64 = 50;
const DEFAULT_LOG_ROTATION_INTERVAL_HOURS: u64 = 24;
const DEFAULT_LOG_MAX_FILES: usize = 5;

#[cfg(not(test))]
const DEFAULT_CONFIG_FILE: &str = "config.toml";
Expand DownExpand Up@@ -56,6 +59,10 @@ pub struct Config {
pub lsps2_service_config: Option<LSPS2ServiceConfig>,
pub log_level: LevelFilter,
pub log_file_path: Option<String>,
pub log_max_size_bytes: usize,
pub log_rotation_interval_secs: u64,
pub log_max_files: usize,
pub log_to_file: bool,
pub pathfinding_scores_source_url: Option<String>,
pub metrics_enabled: bool,
pub poll_metrics_interval: Option<u64>,
Expand DownExpand Up@@ -110,6 +117,10 @@ struct ConfigBuilder {
lsps2: Option<LiquidityConfig>,
log_level: Option<String>,
log_file_path: Option<String>,
log_max_size_mb: Option<u64>,
log_rotation_interval_hours: Option<u64>,
log_max_files: Option<usize>,
log_to_file: Option<bool>,
pathfinding_scores_source_url: Option<String>,
metrics_enabled: Option<bool>,
poll_metrics_interval: Option<u64>,
Expand DownExpand Up@@ -158,6 +169,11 @@ impl ConfigBuilder {
if let Some(log) = toml.log {
self.log_level = log.level.or(self.log_level.clone());
self.log_file_path = log.file.or(self.log_file_path.clone());
self.log_max_size_mb = log.max_size_mb.or(self.log_max_size_mb);
self.log_rotation_interval_hours =
log.rotation_interval_hours.or(self.log_rotation_interval_hours);
self.log_max_files = log.max_files.or(self.log_max_files);
self.log_to_file = log.log_to_file.or(self.log_to_file);
}

if let Some(liquidity) = toml.liquidity {
Expand DownExpand Up@@ -249,6 +265,22 @@ impl ConfigBuilder {
if let Some(tor_proxy_address) = &args.tor_proxy_address {
self.tor_proxy_address = Some(tor_proxy_address.clone());
}

if let Some(log_max_size_mb) = args.log_max_size_mb {
self.log_max_size_mb = Some(log_max_size_mb);
}

if let Some(log_rotation_interval_hours) = args.log_rotation_interval_hours {
self.log_rotation_interval_hours = Some(log_rotation_interval_hours);
}

if let Some(log_max_files) = args.log_max_files {
self.log_max_files = Some(log_max_files);
}

if let Some(log_to_file) = args.log_to_file {
self.log_to_file = Some(log_to_file);
}
}

fn build(self) -> io::Result<Config> {
Expand DownExpand Up@@ -358,6 +390,14 @@ impl ConfigBuilder {
.transpose()?
.unwrap_or(LevelFilter::Debug);

let log_max_size_bytes =
self.log_max_size_mb.unwrap_or(DEFAULT_LOG_MAX_SIZE_MB) * 1024 * 1024;
let log_rotation_interval_secs =
self.log_rotation_interval_hours.unwrap_or(DEFAULT_LOG_ROTATION_INTERVAL_HOURS)
* 60 * 60;
let log_max_files = self.log_max_files.unwrap_or(DEFAULT_LOG_MAX_FILES);
let log_to_file = self.log_to_file.unwrap_or(true);

let lsps2_client_config = self
.lsps2
.as_ref()
Expand DownExpand Up@@ -428,6 +468,10 @@ impl ConfigBuilder {
lsps2_service_config,
log_level,
log_file_path: self.log_file_path,
log_max_size_bytes: log_max_size_bytes as usize,
log_rotation_interval_secs,
log_max_files,
log_to_file,
pathfinding_scores_source_url,
metrics_enabled,
poll_metrics_interval,
Expand DownExpand Up@@ -497,6 +541,10 @@ struct EsploraConfig {
struct LogConfig {
level: Option<String>,
file: Option<String>,
max_size_mb: Option<u64>,
rotation_interval_hours: Option<u64>,
max_files: Option<usize>,
log_to_file: Option<bool>,
}

#[derive(Deserialize, Serialize)]
Expand DownExpand Up@@ -733,6 +781,34 @@ pub struct ArgsConfig {
)]
node_alias: Option<String>,

#[arg(
long,
env = "LDK_SERVER_LOG_MAX_SIZE_MB",
help = "The maximum size of the log file in MB before rotation. Defaults to 50MB."
)]
log_max_size_mb: Option<u64>,

#[arg(
long,
env = "LDK_SERVER_LOG_ROTATION_INTERVAL_HOURS",
help = "The maximum age of the log file in hours before rotation. Defaults to 24h."
)]
log_rotation_interval_hours: Option<u64>,

#[arg(
long,
env = "LDK_SERVER_LOG_MAX_FILES",
help = "The maximum number of rotated log files to keep. Defaults to 5."
)]
log_max_files: Option<usize>,

#[arg(
long,
env = "LDK_SERVER_LOG_TO_FILE",
help = "The option to enable logging to a file. Defaults to true. If false, logging to file is disabled."
)]
log_to_file: Option<bool>,

#[arg(
long,
env = "LDK_SERVER_BITCOIND_RPC_ADDRESS",
Expand DownExpand Up@@ -896,6 +972,10 @@ mod tests {
[log]
level = "Trace"
file = "/var/log/ldk-server.log"
max_size_mb = 50
rotation_interval_hours = 24
max_files = 5
log_to_file = true

[bitcoind]
rpc_address = "127.0.0.1:8332"
Expand DownExpand Up@@ -941,6 +1021,10 @@ mod tests {
metrics_username: None,
metrics_password: None,
tor_proxy_address: None,
log_to_file: Some(true),
log_max_size_mb: Some(50),
log_rotation_interval_hours: Some(24),
log_max_files: Some(5),
}
}

Expand All@@ -962,6 +1046,10 @@ mod tests {
metrics_username: None,
metrics_password: None,
tor_proxy_address: None,
log_to_file: Some(true),
log_max_size_mb: None,
log_rotation_interval_hours: None,
log_max_files: None,
}
}

Expand DownExpand Up@@ -1029,6 +1117,10 @@ mod tests {
}),
log_level: LevelFilter::Trace,
log_file_path: Some("/var/log/ldk-server.log".to_string()),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: true,
pathfinding_scores_source_url: None,
metrics_enabled: false,
poll_metrics_interval: None,
Expand DownExpand Up@@ -1344,6 +1436,10 @@ mod tests {
metrics_password: None,
tor_config: None,
hrn_config: HumanReadableNamesConfig::default(),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: true,
};

assert_eq!(config.listening_addrs, expected.listening_addrs);
Expand All@@ -1357,6 +1453,10 @@ mod tests {
assert_eq!(config.pathfinding_scores_source_url, expected.pathfinding_scores_source_url);
assert_eq!(config.metrics_enabled, expected.metrics_enabled);
assert_eq!(config.tor_config, expected.tor_config);
assert_eq!(config.log_max_size_bytes, expected.log_max_size_bytes);
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);
}

#[test]
Expand DownExpand Up@@ -1454,6 +1554,10 @@ mod tests {
proxy_address: SocketAddress::from_str("127.0.0.1:9050").unwrap(),
}),
hrn_config: HumanReadableNamesConfig::default(),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: false,
};

assert_eq!(config.listening_addrs, expected.listening_addrs);
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
8 changes: 8 additions & 0 deletions contrib/ldk-server-config.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,14 @@ dir_path = "/tmp/ldk-server/" # Path for LDK and BDK data persis
[log]
level = "Debug" # Log level (Error, Warn, Info, Debug, Trace)
#file = "/tmp/ldk-server/ldk-server.log" # Log file path
# Enabling `log_to_file` writes logs to the configured file while still keeping
# the `stdout`/`stderr` logs available too. Logs files are automatically rotated at # `max_size_mb` or `rotation_interval_hours`.
#
# To disable the internal rotation and keep logging to file, set `max_size_mb` # and `rotation_interval_hours` params to `0`.
log_to_file = true # Enable logging to a file (default: true, also logs to both stdout and stderr)
#max_size_mb = 50 # Max size of log file before rotation (default: 50MB)
#rotation_interval_hours = 24 # Max age of log file before rotation (default: 24h)
Comment thread
Anyitechs marked this conversation as resolved.
#max_files = 5 # Number of rotated log files to keep (default: 5)

[tls]
#cert_path = "/path/to/tls.crt" # Path to TLS certificate, by default uses dir_path/tls.crt
Expand Down
12 changes: 10 additions & 2 deletions docs/configuration.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,8 +61,16 @@ Where persistent data is stored. Defaults to `~/.ldk-server/` on Linux and

### `[log]`

Log level and file path. The server reopens the log file on `SIGHUP`, which integrates with
standard `logrotate` setups.
Controls logging behavior. By default, `log_to_file` is `true` and logs are also written
to `stdout`/`stderr`.

If `log_to_file` is enabled, logs are written to the configured file while still keeping
the `stdout`/`stderr` logs available too. Logs files are automatically rotated at
`max_size_mb` or `rotation_interval_hours`. To disable the internal rotation and keep
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`.

### `[tls]`

Expand Down
16 changes: 10 additions & 6 deletions docs/operations.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,13 +21,17 @@ The server handles `SIGTERM` and `CTRL-C` (SIGINT). On receipt, it:

### Log Rotation

> **Important:** LDK Server does not rotate or truncate its own log file. Without log rotation
> configured, the log file will grow indefinitely and can eventually fill your disk. A full
> disk can prevent the node from persisting channel state, risking fund loss.
By default, LDK Server logs to `stdout`/`stderr` and also to file. When running under `systemd` or Docker,
this allows the environment (e.g., `journald`) to handle persistence, rotation, and
compression automatically.

The server reopens its log file on `SIGHUP`. This integrates with standard `logrotate`. Save
the following config to `/etc/logrotate.d/ldk-server` (adjust the log path to match your
setup):
If you enable `log_to_file` in the configuration, LDK Server writes logs to the configured file while still
keeping the `stdout`/`stderr` logs available too. Logs files are automatically rotated at `max_size_mb` or `rotation_interval_hours`, and the last `max_files` uncompressed log files are retained. But you can disable
the internal rotation and keep logging to file by setting the `max_size_mb` and `rotation_interval_hours`
params to `0`.

If you prefer to use system `logrotate` for file logs, the server still reopens its log file on `SIGHUP`. Save
the following config to `/etc/logrotate.d/ldk-server` (adjust the log path to match your setup):

```
/var/lib/ldk-server/regtest/ldk-server.log {
Expand Down
35 changes: 24 additions & 11 deletions ldk-server/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,7 @@ use crate::io::persist::{
};
use crate::service::NodeService;
use crate::util::config::{load_config, ArgsConfig, ChainSource};
use crate::util::logger::ServerLogger;
use crate::util::logger::{LogConfig, ServerLogger};
use crate::util::metrics::Metrics;
use crate::util::proto_adapter::{forwarded_payment_to_proto, payment_to_proto};
use crate::util::systemd;
Expand DownExpand Up@@ -110,18 +110,29 @@ fn main() {
Network::Regtest => storage_dir.join("regtest"),
};

let log_file_path = config_file.log_file_path.map(PathBuf::from).unwrap_or_else(|| {
let mut default_log_path = network_dir.clone();
default_log_path.push("ldk-server.log");
default_log_path
});
let log_file_path = if config_file.log_to_file {
let path = config_file.log_file_path.map(PathBuf::from).unwrap_or_else(|| {
let mut default_log_path = network_dir.clone();
default_log_path.push("ldk-server.log");
default_log_path
});

if log_file_path == storage_dir || log_file_path == network_dir {
eprintln!("Log file path cannot be the same as storage directory path.");
std::process::exit(-1);
}
if path == storage_dir || path == network_dir {
eprintln!("Log file path cannot be the same as storage directory path.");
std::process::exit(-1);
}
Some(path)
} else {
None
};

let log_config = LogConfig {
log_max_files: config_file.log_max_files,
log_max_size_bytes: config_file.log_max_size_bytes,
log_rotation_interval_secs: config_file.log_rotation_interval_secs,
};

let logger = match ServerLogger::init(config_file.log_level, &log_file_path) {
let logger = match ServerLogger::init(config_file.log_level, log_file_path, log_config) {
Ok(logger) => logger,
Err(e) => {
eprintln!("Failed to initialize logger: {e}");
Expand DownExpand Up@@ -519,6 +530,7 @@ fn main() {
break;
}
_ = sighup_stream.recv() => {
info!("Received SIGHUP, reopening log file..");
if let Err(e) = logger.reopen() {
error!("Failed to reopen log file on SIGHUP: {e}");
}
Expand All@@ -535,6 +547,7 @@ fn main() {
systemd::notify_stopping();
node.stop().expect("Shutdown should always succeed.");
info!("Shutdown complete..");
log::logger().flush();
}

fn send_event_and_upsert_payment(
Expand Down
104 changes: 104 additions & 0 deletions ldk-server/src/util/config.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,9 @@ use log::LevelFilter;
use serde::{Deserialize, Serialize};

const DEFAULT_GRPC_SERVICE_ADDRESS: &str = "127.0.0.1:3536";
const DEFAULT_LOG_MAX_SIZE_MB: u64 = 50;
const DEFAULT_LOG_ROTATION_INTERVAL_HOURS: u64 = 24;
const DEFAULT_LOG_MAX_FILES: usize = 5;

#[cfg(not(test))]
const DEFAULT_CONFIG_FILE: &str = "config.toml";
Expand DownExpand Up@@ -56,6 +59,10 @@ pub struct Config {
pub lsps2_service_config: Option<LSPS2ServiceConfig>,
pub log_level: LevelFilter,
pub log_file_path: Option<String>,
pub log_max_size_bytes: usize,
pub log_rotation_interval_secs: u64,
pub log_max_files: usize,
pub log_to_file: bool,
pub pathfinding_scores_source_url: Option<String>,
pub metrics_enabled: bool,
pub poll_metrics_interval: Option<u64>,
Expand DownExpand Up@@ -110,6 +117,10 @@ struct ConfigBuilder {
lsps2: Option<LiquidityConfig>,
log_level: Option<String>,
log_file_path: Option<String>,
log_max_size_mb: Option<u64>,
log_rotation_interval_hours: Option<u64>,
log_max_files: Option<usize>,
log_to_file: Option<bool>,
pathfinding_scores_source_url: Option<String>,
metrics_enabled: Option<bool>,
poll_metrics_interval: Option<u64>,
Expand DownExpand Up@@ -158,6 +169,11 @@ impl ConfigBuilder {
if let Some(log) = toml.log {
self.log_level = log.level.or(self.log_level.clone());
self.log_file_path = log.file.or(self.log_file_path.clone());
self.log_max_size_mb = log.max_size_mb.or(self.log_max_size_mb);
self.log_rotation_interval_hours =
log.rotation_interval_hours.or(self.log_rotation_interval_hours);
self.log_max_files = log.max_files.or(self.log_max_files);
self.log_to_file = log.log_to_file.or(self.log_to_file);
}

if let Some(liquidity) = toml.liquidity {
Expand DownExpand Up@@ -249,6 +265,22 @@ impl ConfigBuilder {
if let Some(tor_proxy_address) = &args.tor_proxy_address {
self.tor_proxy_address = Some(tor_proxy_address.clone());
}

if let Some(log_max_size_mb) = args.log_max_size_mb {
self.log_max_size_mb = Some(log_max_size_mb);
}

if let Some(log_rotation_interval_hours) = args.log_rotation_interval_hours {
self.log_rotation_interval_hours = Some(log_rotation_interval_hours);
}

if let Some(log_max_files) = args.log_max_files {
self.log_max_files = Some(log_max_files);
}

if let Some(log_to_file) = args.log_to_file {
self.log_to_file = Some(log_to_file);
}
}

fn build(self) -> io::Result<Config> {
Expand DownExpand Up@@ -358,6 +390,14 @@ impl ConfigBuilder {
.transpose()?
.unwrap_or(LevelFilter::Debug);

let log_max_size_bytes =
self.log_max_size_mb.unwrap_or(DEFAULT_LOG_MAX_SIZE_MB) * 1024 * 1024;
let log_rotation_interval_secs =
self.log_rotation_interval_hours.unwrap_or(DEFAULT_LOG_ROTATION_INTERVAL_HOURS)
* 60 * 60;
let log_max_files = self.log_max_files.unwrap_or(DEFAULT_LOG_MAX_FILES);
let log_to_file = self.log_to_file.unwrap_or(true);

let lsps2_client_config = self
.lsps2
.as_ref()
Expand DownExpand Up@@ -428,6 +468,10 @@ impl ConfigBuilder {
lsps2_service_config,
log_level,
log_file_path: self.log_file_path,
log_max_size_bytes: log_max_size_bytes as usize,
log_rotation_interval_secs,
log_max_files,
log_to_file,
pathfinding_scores_source_url,
metrics_enabled,
poll_metrics_interval,
Expand DownExpand Up@@ -497,6 +541,10 @@ struct EsploraConfig {
struct LogConfig {
level: Option<String>,
file: Option<String>,
max_size_mb: Option<u64>,
rotation_interval_hours: Option<u64>,
max_files: Option<usize>,
log_to_file: Option<bool>,
}

#[derive(Deserialize, Serialize)]
Expand DownExpand Up@@ -733,6 +781,34 @@ pub struct ArgsConfig {
)]
node_alias: Option<String>,

#[arg(
long,
env = "LDK_SERVER_LOG_MAX_SIZE_MB",
help = "The maximum size of the log file in MB before rotation. Defaults to 50MB."
)]
log_max_size_mb: Option<u64>,

#[arg(
long,
env = "LDK_SERVER_LOG_ROTATION_INTERVAL_HOURS",
help = "The maximum age of the log file in hours before rotation. Defaults to 24h."
)]
log_rotation_interval_hours: Option<u64>,

#[arg(
long,
env = "LDK_SERVER_LOG_MAX_FILES",
help = "The maximum number of rotated log files to keep. Defaults to 5."
)]
log_max_files: Option<usize>,

#[arg(
long,
env = "LDK_SERVER_LOG_TO_FILE",
help = "The option to enable logging to a file. Defaults to true. If false, logging to file is disabled."
)]
log_to_file: Option<bool>,

#[arg(
long,
env = "LDK_SERVER_BITCOIND_RPC_ADDRESS",
Expand DownExpand Up@@ -896,6 +972,10 @@ mod tests {
[log]
level = "Trace"
file = "/var/log/ldk-server.log"
max_size_mb = 50
rotation_interval_hours = 24
max_files = 5
log_to_file = true

[bitcoind]
rpc_address = "127.0.0.1:8332"
Expand DownExpand Up@@ -941,6 +1021,10 @@ mod tests {
metrics_username: None,
metrics_password: None,
tor_proxy_address: None,
log_to_file: Some(true),
log_max_size_mb: Some(50),
log_rotation_interval_hours: Some(24),
log_max_files: Some(5),
}
}

Expand All@@ -962,6 +1046,10 @@ mod tests {
metrics_username: None,
metrics_password: None,
tor_proxy_address: None,
log_to_file: Some(true),
log_max_size_mb: None,
log_rotation_interval_hours: None,
log_max_files: None,
}
}

Expand DownExpand Up@@ -1029,6 +1117,10 @@ mod tests {
}),
log_level: LevelFilter::Trace,
log_file_path: Some("/var/log/ldk-server.log".to_string()),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: true,
pathfinding_scores_source_url: None,
metrics_enabled: false,
poll_metrics_interval: None,
Expand DownExpand Up@@ -1344,6 +1436,10 @@ mod tests {
metrics_password: None,
tor_config: None,
hrn_config: HumanReadableNamesConfig::default(),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: true,
};

assert_eq!(config.listening_addrs, expected.listening_addrs);
Expand All@@ -1357,6 +1453,10 @@ mod tests {
assert_eq!(config.pathfinding_scores_source_url, expected.pathfinding_scores_source_url);
assert_eq!(config.metrics_enabled, expected.metrics_enabled);
assert_eq!(config.tor_config, expected.tor_config);
assert_eq!(config.log_max_size_bytes, expected.log_max_size_bytes);
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);
}

#[test]
Expand DownExpand Up@@ -1454,6 +1554,10 @@ mod tests {
proxy_address: SocketAddress::from_str("127.0.0.1:9050").unwrap(),
}),
hrn_config: HumanReadableNamesConfig::default(),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: false,
};

assert_eq!(config.listening_addrs, expected.listening_addrs);
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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
8 changes: 8 additions & 0 deletions contrib/ldk-server-config.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,14 @@ dir_path = "/tmp/ldk-server/" # Path for LDK and BDK data persis
[log]
level = "Debug" # Log level (Error, Warn, Info, Debug, Trace)
#file = "/tmp/ldk-server/ldk-server.log" # Log file path
# Enabling `log_to_file` writes logs to the configured file while still keeping
# the `stdout`/`stderr` logs available too. Logs files are automatically rotated at # `max_size_mb` or `rotation_interval_hours`.
#
# To disable the internal rotation and keep logging to file, set `max_size_mb` # and `rotation_interval_hours` params to `0`.
log_to_file = true # Enable logging to a file (default: true, also logs to both stdout and stderr)
#max_size_mb = 50 # Max size of log file before rotation (default: 50MB)
#rotation_interval_hours = 24 # Max age of log file before rotation (default: 24h)
Comment thread
Anyitechs marked this conversation as resolved.
#max_files = 5 # Number of rotated log files to keep (default: 5)

[tls]
#cert_path = "/path/to/tls.crt" # Path to TLS certificate, by default uses dir_path/tls.crt
Expand Down
12 changes: 10 additions & 2 deletions docs/configuration.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,8 +61,16 @@ Where persistent data is stored. Defaults to `~/.ldk-server/` on Linux and

### `[log]`

Log level and file path. The server reopens the log file on `SIGHUP`, which integrates with
standard `logrotate` setups.
Controls logging behavior. By default, `log_to_file` is `true` and logs are also written
to `stdout`/`stderr`.

If `log_to_file` is enabled, logs are written to the configured file while still keeping
the `stdout`/`stderr` logs available too. Logs files are automatically rotated at
`max_size_mb` or `rotation_interval_hours`. To disable the internal rotation and keep
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`.

### `[tls]`

Expand Down
16 changes: 10 additions & 6 deletions docs/operations.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,13 +21,17 @@ The server handles `SIGTERM` and `CTRL-C` (SIGINT). On receipt, it:

### Log Rotation

> **Important:** LDK Server does not rotate or truncate its own log file. Without log rotation
> configured, the log file will grow indefinitely and can eventually fill your disk. A full
> disk can prevent the node from persisting channel state, risking fund loss.
By default, LDK Server logs to `stdout`/`stderr` and also to file. When running under `systemd` or Docker,
this allows the environment (e.g., `journald`) to handle persistence, rotation, and
compression automatically.

The server reopens its log file on `SIGHUP`. This integrates with standard `logrotate`. Save
the following config to `/etc/logrotate.d/ldk-server` (adjust the log path to match your
setup):
If you enable `log_to_file` in the configuration, LDK Server writes logs to the configured file while still
keeping the `stdout`/`stderr` logs available too. Logs files are automatically rotated at `max_size_mb` or `rotation_interval_hours`, and the last `max_files` uncompressed log files are retained. But you can disable
the internal rotation and keep logging to file by setting the `max_size_mb` and `rotation_interval_hours`
params to `0`.

If you prefer to use system `logrotate` for file logs, the server still reopens its log file on `SIGHUP`. Save
the following config to `/etc/logrotate.d/ldk-server` (adjust the log path to match your setup):

```
/var/lib/ldk-server/regtest/ldk-server.log {
Expand Down
35 changes: 24 additions & 11 deletions ldk-server/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,7 @@ use crate::io::persist::{
};
use crate::service::NodeService;
use crate::util::config::{load_config, ArgsConfig, ChainSource};
use crate::util::logger::ServerLogger;
use crate::util::logger::{LogConfig, ServerLogger};
use crate::util::metrics::Metrics;
use crate::util::proto_adapter::{forwarded_payment_to_proto, payment_to_proto};
use crate::util::systemd;
Expand DownExpand Up@@ -110,18 +110,29 @@ fn main() {
Network::Regtest => storage_dir.join("regtest"),
};

let log_file_path = config_file.log_file_path.map(PathBuf::from).unwrap_or_else(|| {
let mut default_log_path = network_dir.clone();
default_log_path.push("ldk-server.log");
default_log_path
});
let log_file_path = if config_file.log_to_file {
let path = config_file.log_file_path.map(PathBuf::from).unwrap_or_else(|| {
let mut default_log_path = network_dir.clone();
default_log_path.push("ldk-server.log");
default_log_path
});

if log_file_path == storage_dir || log_file_path == network_dir {
eprintln!("Log file path cannot be the same as storage directory path.");
std::process::exit(-1);
}
if path == storage_dir || path == network_dir {
eprintln!("Log file path cannot be the same as storage directory path.");
std::process::exit(-1);
}
Some(path)
} else {
None
};

let log_config = LogConfig {
log_max_files: config_file.log_max_files,
log_max_size_bytes: config_file.log_max_size_bytes,
log_rotation_interval_secs: config_file.log_rotation_interval_secs,
};

let logger = match ServerLogger::init(config_file.log_level, &log_file_path) {
let logger = match ServerLogger::init(config_file.log_level, log_file_path, log_config) {
Ok(logger) => logger,
Err(e) => {
eprintln!("Failed to initialize logger: {e}");
Expand DownExpand Up@@ -519,6 +530,7 @@ fn main() {
break;
}
_ = sighup_stream.recv() => {
info!("Received SIGHUP, reopening log file..");
if let Err(e) = logger.reopen() {
error!("Failed to reopen log file on SIGHUP: {e}");
}
Expand All@@ -535,6 +547,7 @@ fn main() {
systemd::notify_stopping();
node.stop().expect("Shutdown should always succeed.");
info!("Shutdown complete..");
log::logger().flush();
}

fn send_event_and_upsert_payment(
Expand Down
104 changes: 104 additions & 0 deletions ldk-server/src/util/config.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,9 @@ use log::LevelFilter;
use serde::{Deserialize, Serialize};

const DEFAULT_GRPC_SERVICE_ADDRESS: &str = "127.0.0.1:3536";
const DEFAULT_LOG_MAX_SIZE_MB: u64 = 50;
const DEFAULT_LOG_ROTATION_INTERVAL_HOURS: u64 = 24;
const DEFAULT_LOG_MAX_FILES: usize = 5;

#[cfg(not(test))]
const DEFAULT_CONFIG_FILE: &str = "config.toml";
Expand DownExpand Up@@ -56,6 +59,10 @@ pub struct Config {
pub lsps2_service_config: Option<LSPS2ServiceConfig>,
pub log_level: LevelFilter,
pub log_file_path: Option<String>,
pub log_max_size_bytes: usize,
pub log_rotation_interval_secs: u64,
pub log_max_files: usize,
pub log_to_file: bool,
pub pathfinding_scores_source_url: Option<String>,
pub metrics_enabled: bool,
pub poll_metrics_interval: Option<u64>,
Expand DownExpand Up@@ -110,6 +117,10 @@ struct ConfigBuilder {
lsps2: Option<LiquidityConfig>,
log_level: Option<String>,
log_file_path: Option<String>,
log_max_size_mb: Option<u64>,
log_rotation_interval_hours: Option<u64>,
log_max_files: Option<usize>,
log_to_file: Option<bool>,
pathfinding_scores_source_url: Option<String>,
metrics_enabled: Option<bool>,
poll_metrics_interval: Option<u64>,
Expand DownExpand Up@@ -158,6 +169,11 @@ impl ConfigBuilder {
if let Some(log) = toml.log {
self.log_level = log.level.or(self.log_level.clone());
self.log_file_path = log.file.or(self.log_file_path.clone());
self.log_max_size_mb = log.max_size_mb.or(self.log_max_size_mb);
self.log_rotation_interval_hours =
log.rotation_interval_hours.or(self.log_rotation_interval_hours);
self.log_max_files = log.max_files.or(self.log_max_files);
self.log_to_file = log.log_to_file.or(self.log_to_file);
}

if let Some(liquidity) = toml.liquidity {
Expand DownExpand Up@@ -249,6 +265,22 @@ impl ConfigBuilder {
if let Some(tor_proxy_address) = &args.tor_proxy_address {
self.tor_proxy_address = Some(tor_proxy_address.clone());
}

if let Some(log_max_size_mb) = args.log_max_size_mb {
self.log_max_size_mb = Some(log_max_size_mb);
}

if let Some(log_rotation_interval_hours) = args.log_rotation_interval_hours {
self.log_rotation_interval_hours = Some(log_rotation_interval_hours);
}

if let Some(log_max_files) = args.log_max_files {
self.log_max_files = Some(log_max_files);
}

if let Some(log_to_file) = args.log_to_file {
self.log_to_file = Some(log_to_file);
}
}

fn build(self) -> io::Result<Config> {
Expand DownExpand Up@@ -358,6 +390,14 @@ impl ConfigBuilder {
.transpose()?
.unwrap_or(LevelFilter::Debug);

let log_max_size_bytes =
self.log_max_size_mb.unwrap_or(DEFAULT_LOG_MAX_SIZE_MB) * 1024 * 1024;
let log_rotation_interval_secs =
self.log_rotation_interval_hours.unwrap_or(DEFAULT_LOG_ROTATION_INTERVAL_HOURS)
* 60 * 60;
let log_max_files = self.log_max_files.unwrap_or(DEFAULT_LOG_MAX_FILES);
let log_to_file = self.log_to_file.unwrap_or(true);

let lsps2_client_config = self
.lsps2
.as_ref()
Expand DownExpand Up@@ -428,6 +468,10 @@ impl ConfigBuilder {
lsps2_service_config,
log_level,
log_file_path: self.log_file_path,
log_max_size_bytes: log_max_size_bytes as usize,
log_rotation_interval_secs,
log_max_files,
log_to_file,
pathfinding_scores_source_url,
metrics_enabled,
poll_metrics_interval,
Expand DownExpand Up@@ -497,6 +541,10 @@ struct EsploraConfig {
struct LogConfig {
level: Option<String>,
file: Option<String>,
max_size_mb: Option<u64>,
rotation_interval_hours: Option<u64>,
max_files: Option<usize>,
log_to_file: Option<bool>,
}

#[derive(Deserialize, Serialize)]
Expand DownExpand Up@@ -733,6 +781,34 @@ pub struct ArgsConfig {
)]
node_alias: Option<String>,

#[arg(
long,
env = "LDK_SERVER_LOG_MAX_SIZE_MB",
help = "The maximum size of the log file in MB before rotation. Defaults to 50MB."
)]
log_max_size_mb: Option<u64>,

#[arg(
long,
env = "LDK_SERVER_LOG_ROTATION_INTERVAL_HOURS",
help = "The maximum age of the log file in hours before rotation. Defaults to 24h."
)]
log_rotation_interval_hours: Option<u64>,

#[arg(
long,
env = "LDK_SERVER_LOG_MAX_FILES",
help = "The maximum number of rotated log files to keep. Defaults to 5."
)]
log_max_files: Option<usize>,

#[arg(
long,
env = "LDK_SERVER_LOG_TO_FILE",
help = "The option to enable logging to a file. Defaults to true. If false, logging to file is disabled."
)]
log_to_file: Option<bool>,

#[arg(
long,
env = "LDK_SERVER_BITCOIND_RPC_ADDRESS",
Expand DownExpand Up@@ -896,6 +972,10 @@ mod tests {
[log]
level = "Trace"
file = "/var/log/ldk-server.log"
max_size_mb = 50
rotation_interval_hours = 24
max_files = 5
log_to_file = true

[bitcoind]
rpc_address = "127.0.0.1:8332"
Expand DownExpand Up@@ -941,6 +1021,10 @@ mod tests {
metrics_username: None,
metrics_password: None,
tor_proxy_address: None,
log_to_file: Some(true),
log_max_size_mb: Some(50),
log_rotation_interval_hours: Some(24),
log_max_files: Some(5),
}
}

Expand All@@ -962,6 +1046,10 @@ mod tests {
metrics_username: None,
metrics_password: None,
tor_proxy_address: None,
log_to_file: Some(true),
log_max_size_mb: None,
log_rotation_interval_hours: None,
log_max_files: None,
}
}

Expand DownExpand Up@@ -1029,6 +1117,10 @@ mod tests {
}),
log_level: LevelFilter::Trace,
log_file_path: Some("/var/log/ldk-server.log".to_string()),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: true,
pathfinding_scores_source_url: None,
metrics_enabled: false,
poll_metrics_interval: None,
Expand DownExpand Up@@ -1344,6 +1436,10 @@ mod tests {
metrics_password: None,
tor_config: None,
hrn_config: HumanReadableNamesConfig::default(),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: true,
};

assert_eq!(config.listening_addrs, expected.listening_addrs);
Expand All@@ -1357,6 +1453,10 @@ mod tests {
assert_eq!(config.pathfinding_scores_source_url, expected.pathfinding_scores_source_url);
assert_eq!(config.metrics_enabled, expected.metrics_enabled);
assert_eq!(config.tor_config, expected.tor_config);
assert_eq!(config.log_max_size_bytes, expected.log_max_size_bytes);
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);
}

#[test]
Expand DownExpand Up@@ -1454,6 +1554,10 @@ mod tests {
proxy_address: SocketAddress::from_str("127.0.0.1:9050").unwrap(),
}),
hrn_config: HumanReadableNamesConfig::default(),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: false,
};

assert_eq!(config.listening_addrs, expected.listening_addrs);
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
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
8 changes: 8 additions & 0 deletions contrib/ldk-server-config.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,14 @@ dir_path = "/tmp/ldk-server/" # Path for LDK and BDK data persis
[log]
level = "Debug" # Log level (Error, Warn, Info, Debug, Trace)
#file = "/tmp/ldk-server/ldk-server.log" # Log file path
# Enabling `log_to_file` writes logs to the configured file while still keeping
# the `stdout`/`stderr` logs available too. Logs files are automatically rotated at # `max_size_mb` or `rotation_interval_hours`.
#
# To disable the internal rotation and keep logging to file, set `max_size_mb` # and `rotation_interval_hours` params to `0`.
log_to_file = true # Enable logging to a file (default: true, also logs to both stdout and stderr)
#max_size_mb = 50 # Max size of log file before rotation (default: 50MB)
#rotation_interval_hours = 24 # Max age of log file before rotation (default: 24h)
Comment thread
Anyitechs marked this conversation as resolved.
#max_files = 5 # Number of rotated log files to keep (default: 5)

[tls]
#cert_path = "/path/to/tls.crt" # Path to TLS certificate, by default uses dir_path/tls.crt
Expand Down
12 changes: 10 additions & 2 deletions docs/configuration.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,8 +61,16 @@ Where persistent data is stored. Defaults to `~/.ldk-server/` on Linux and

### `[log]`

Log level and file path. The server reopens the log file on `SIGHUP`, which integrates with
standard `logrotate` setups.
Controls logging behavior. By default, `log_to_file` is `true` and logs are also written
to `stdout`/`stderr`.

If `log_to_file` is enabled, logs are written to the configured file while still keeping
the `stdout`/`stderr` logs available too. Logs files are automatically rotated at
`max_size_mb` or `rotation_interval_hours`. To disable the internal rotation and keep
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`.

### `[tls]`

Expand Down
16 changes: 10 additions & 6 deletions docs/operations.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,13 +21,17 @@ The server handles `SIGTERM` and `CTRL-C` (SIGINT). On receipt, it:

### Log Rotation

> **Important:** LDK Server does not rotate or truncate its own log file. Without log rotation
> configured, the log file will grow indefinitely and can eventually fill your disk. A full
> disk can prevent the node from persisting channel state, risking fund loss.
By default, LDK Server logs to `stdout`/`stderr` and also to file. When running under `systemd` or Docker,
this allows the environment (e.g., `journald`) to handle persistence, rotation, and
compression automatically.

The server reopens its log file on `SIGHUP`. This integrates with standard `logrotate`. Save
the following config to `/etc/logrotate.d/ldk-server` (adjust the log path to match your
setup):
If you enable `log_to_file` in the configuration, LDK Server writes logs to the configured file while still
keeping the `stdout`/`stderr` logs available too. Logs files are automatically rotated at `max_size_mb` or `rotation_interval_hours`, and the last `max_files` uncompressed log files are retained. But you can disable
the internal rotation and keep logging to file by setting the `max_size_mb` and `rotation_interval_hours`
params to `0`.

If you prefer to use system `logrotate` for file logs, the server still reopens its log file on `SIGHUP`. Save
the following config to `/etc/logrotate.d/ldk-server` (adjust the log path to match your setup):

```
/var/lib/ldk-server/regtest/ldk-server.log {
Expand Down
35 changes: 24 additions & 11 deletions ldk-server/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,7 @@ use crate::io::persist::{
};
use crate::service::NodeService;
use crate::util::config::{load_config, ArgsConfig, ChainSource};
use crate::util::logger::ServerLogger;
use crate::util::logger::{LogConfig, ServerLogger};
use crate::util::metrics::Metrics;
use crate::util::proto_adapter::{forwarded_payment_to_proto, payment_to_proto};
use crate::util::systemd;
Expand DownExpand Up@@ -110,18 +110,29 @@ fn main() {
Network::Regtest => storage_dir.join("regtest"),
};

let log_file_path = config_file.log_file_path.map(PathBuf::from).unwrap_or_else(|| {
let mut default_log_path = network_dir.clone();
default_log_path.push("ldk-server.log");
default_log_path
});
let log_file_path = if config_file.log_to_file {
let path = config_file.log_file_path.map(PathBuf::from).unwrap_or_else(|| {
let mut default_log_path = network_dir.clone();
default_log_path.push("ldk-server.log");
default_log_path
});

if log_file_path == storage_dir || log_file_path == network_dir {
eprintln!("Log file path cannot be the same as storage directory path.");
std::process::exit(-1);
}
if path == storage_dir || path == network_dir {
eprintln!("Log file path cannot be the same as storage directory path.");
std::process::exit(-1);
}
Some(path)
} else {
None
};

let log_config = LogConfig {
log_max_files: config_file.log_max_files,
log_max_size_bytes: config_file.log_max_size_bytes,
log_rotation_interval_secs: config_file.log_rotation_interval_secs,
};

let logger = match ServerLogger::init(config_file.log_level, &log_file_path) {
let logger = match ServerLogger::init(config_file.log_level, log_file_path, log_config) {
Ok(logger) => logger,
Err(e) => {
eprintln!("Failed to initialize logger: {e}");
Expand DownExpand Up@@ -519,6 +530,7 @@ fn main() {
break;
}
_ = sighup_stream.recv() => {
info!("Received SIGHUP, reopening log file..");
if let Err(e) = logger.reopen() {
error!("Failed to reopen log file on SIGHUP: {e}");
}
Expand All@@ -535,6 +547,7 @@ fn main() {
systemd::notify_stopping();
node.stop().expect("Shutdown should always succeed.");
info!("Shutdown complete..");
log::logger().flush();
}

fn send_event_and_upsert_payment(
Expand Down
104 changes: 104 additions & 0 deletions ldk-server/src/util/config.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,9 @@ use log::LevelFilter;
use serde::{Deserialize, Serialize};

const DEFAULT_GRPC_SERVICE_ADDRESS: &str = "127.0.0.1:3536";
const DEFAULT_LOG_MAX_SIZE_MB: u64 = 50;
const DEFAULT_LOG_ROTATION_INTERVAL_HOURS: u64 = 24;
const DEFAULT_LOG_MAX_FILES: usize = 5;

#[cfg(not(test))]
const DEFAULT_CONFIG_FILE: &str = "config.toml";
Expand DownExpand Up@@ -56,6 +59,10 @@ pub struct Config {
pub lsps2_service_config: Option<LSPS2ServiceConfig>,
pub log_level: LevelFilter,
pub log_file_path: Option<String>,
pub log_max_size_bytes: usize,
pub log_rotation_interval_secs: u64,
pub log_max_files: usize,
pub log_to_file: bool,
pub pathfinding_scores_source_url: Option<String>,
pub metrics_enabled: bool,
pub poll_metrics_interval: Option<u64>,
Expand DownExpand Up@@ -110,6 +117,10 @@ struct ConfigBuilder {
lsps2: Option<LiquidityConfig>,
log_level: Option<String>,
log_file_path: Option<String>,
log_max_size_mb: Option<u64>,
log_rotation_interval_hours: Option<u64>,
log_max_files: Option<usize>,
log_to_file: Option<bool>,
pathfinding_scores_source_url: Option<String>,
metrics_enabled: Option<bool>,
poll_metrics_interval: Option<u64>,
Expand DownExpand Up@@ -158,6 +169,11 @@ impl ConfigBuilder {
if let Some(log) = toml.log {
self.log_level = log.level.or(self.log_level.clone());
self.log_file_path = log.file.or(self.log_file_path.clone());
self.log_max_size_mb = log.max_size_mb.or(self.log_max_size_mb);
self.log_rotation_interval_hours =
log.rotation_interval_hours.or(self.log_rotation_interval_hours);
self.log_max_files = log.max_files.or(self.log_max_files);
self.log_to_file = log.log_to_file.or(self.log_to_file);
}

if let Some(liquidity) = toml.liquidity {
Expand DownExpand Up@@ -249,6 +265,22 @@ impl ConfigBuilder {
if let Some(tor_proxy_address) = &args.tor_proxy_address {
self.tor_proxy_address = Some(tor_proxy_address.clone());
}

if let Some(log_max_size_mb) = args.log_max_size_mb {
self.log_max_size_mb = Some(log_max_size_mb);
}

if let Some(log_rotation_interval_hours) = args.log_rotation_interval_hours {
self.log_rotation_interval_hours = Some(log_rotation_interval_hours);
}

if let Some(log_max_files) = args.log_max_files {
self.log_max_files = Some(log_max_files);
}

if let Some(log_to_file) = args.log_to_file {
self.log_to_file = Some(log_to_file);
}
}

fn build(self) -> io::Result<Config> {
Expand DownExpand Up@@ -358,6 +390,14 @@ impl ConfigBuilder {
.transpose()?
.unwrap_or(LevelFilter::Debug);

let log_max_size_bytes =
self.log_max_size_mb.unwrap_or(DEFAULT_LOG_MAX_SIZE_MB) * 1024 * 1024;
let log_rotation_interval_secs =
self.log_rotation_interval_hours.unwrap_or(DEFAULT_LOG_ROTATION_INTERVAL_HOURS)
* 60 * 60;
let log_max_files = self.log_max_files.unwrap_or(DEFAULT_LOG_MAX_FILES);
let log_to_file = self.log_to_file.unwrap_or(true);

let lsps2_client_config = self
.lsps2
.as_ref()
Expand DownExpand Up@@ -428,6 +468,10 @@ impl ConfigBuilder {
lsps2_service_config,
log_level,
log_file_path: self.log_file_path,
log_max_size_bytes: log_max_size_bytes as usize,
log_rotation_interval_secs,
log_max_files,
log_to_file,
pathfinding_scores_source_url,
metrics_enabled,
poll_metrics_interval,
Expand DownExpand Up@@ -497,6 +541,10 @@ struct EsploraConfig {
struct LogConfig {
level: Option<String>,
file: Option<String>,
max_size_mb: Option<u64>,
rotation_interval_hours: Option<u64>,
max_files: Option<usize>,
log_to_file: Option<bool>,
}

#[derive(Deserialize, Serialize)]
Expand DownExpand Up@@ -733,6 +781,34 @@ pub struct ArgsConfig {
)]
node_alias: Option<String>,

#[arg(
long,
env = "LDK_SERVER_LOG_MAX_SIZE_MB",
help = "The maximum size of the log file in MB before rotation. Defaults to 50MB."
)]
log_max_size_mb: Option<u64>,

#[arg(
long,
env = "LDK_SERVER_LOG_ROTATION_INTERVAL_HOURS",
help = "The maximum age of the log file in hours before rotation. Defaults to 24h."
)]
log_rotation_interval_hours: Option<u64>,

#[arg(
long,
env = "LDK_SERVER_LOG_MAX_FILES",
help = "The maximum number of rotated log files to keep. Defaults to 5."
)]
log_max_files: Option<usize>,

#[arg(
long,
env = "LDK_SERVER_LOG_TO_FILE",
help = "The option to enable logging to a file. Defaults to true. If false, logging to file is disabled."
)]
log_to_file: Option<bool>,

#[arg(
long,
env = "LDK_SERVER_BITCOIND_RPC_ADDRESS",
Expand DownExpand Up@@ -896,6 +972,10 @@ mod tests {
[log]
level = "Trace"
file = "/var/log/ldk-server.log"
max_size_mb = 50
rotation_interval_hours = 24
max_files = 5
log_to_file = true

[bitcoind]
rpc_address = "127.0.0.1:8332"
Expand DownExpand Up@@ -941,6 +1021,10 @@ mod tests {
metrics_username: None,
metrics_password: None,
tor_proxy_address: None,
log_to_file: Some(true),
log_max_size_mb: Some(50),
log_rotation_interval_hours: Some(24),
log_max_files: Some(5),
}
}

Expand All@@ -962,6 +1046,10 @@ mod tests {
metrics_username: None,
metrics_password: None,
tor_proxy_address: None,
log_to_file: Some(true),
log_max_size_mb: None,
log_rotation_interval_hours: None,
log_max_files: None,
}
}

Expand DownExpand Up@@ -1029,6 +1117,10 @@ mod tests {
}),
log_level: LevelFilter::Trace,
log_file_path: Some("/var/log/ldk-server.log".to_string()),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: true,
pathfinding_scores_source_url: None,
metrics_enabled: false,
poll_metrics_interval: None,
Expand DownExpand Up@@ -1344,6 +1436,10 @@ mod tests {
metrics_password: None,
tor_config: None,
hrn_config: HumanReadableNamesConfig::default(),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: true,
};

assert_eq!(config.listening_addrs, expected.listening_addrs);
Expand All@@ -1357,6 +1453,10 @@ mod tests {
assert_eq!(config.pathfinding_scores_source_url, expected.pathfinding_scores_source_url);
assert_eq!(config.metrics_enabled, expected.metrics_enabled);
assert_eq!(config.tor_config, expected.tor_config);
assert_eq!(config.log_max_size_bytes, expected.log_max_size_bytes);
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);
}

#[test]
Expand DownExpand Up@@ -1454,6 +1554,10 @@ mod tests {
proxy_address: SocketAddress::from_str("127.0.0.1:9050").unwrap(),
}),
hrn_config: HumanReadableNamesConfig::default(),
log_max_size_bytes: 50 * 1024 * 1024,
log_rotation_interval_secs: 24 * 60 * 60,
log_max_files: 5,
log_to_file: false,
};

assert_eq!(config.listening_addrs, expected.listening_addrs);
Expand Down
Loading
Loading