Skip to content

Commit 4b0de09

Browse files
committed
Add a builder method to customize where logs are stored
1 parent c3aca16 commit 4b0de09

3 files changed

Lines changed: 36 additions & 13 deletions

File tree

bindings/ldk_node.udl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace ldk_node {
44

55
dictionary Config {
66
string storage_dir_path = "/tmp/ldk_node/";
7+
string? log_dir_path = null;
78
Network network = "Bitcoin";
89
NetAddress? listening_address = null;
910
u32 default_cltv_expiry_delta = 144;

src/builder.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ impl NodeBuilder {
202202
self
203203
}
204204

205+
/// Sets the log dir path if logs need to live separate from the storage directory path.
206+
pub fn set_log_dir_path(&mut self, log_dir_path: String) -> &mut Self {
207+
self.config.log_dir_path = Some(log_dir_path);
208+
self
209+
}
210+
205211
/// Sets the Bitcoin network used.
206212
pub fn set_network(&mut self, network: Network) -> &mut Self {
207213
self.config.network = network;
@@ -329,6 +335,11 @@ impl ArcedNodeBuilder {
329335
self.inner.write().unwrap().set_storage_dir_path(storage_dir_path);
330336
}
331337

338+
/// Sets the log dir path if logs need to live separate from the storage directory path.
339+
pub fn set_log_dir_path(&self, log_dir_path: String) {
340+
self.inner.write().unwrap().set_log_dir_path(log_dir_path);
341+
}
342+
332343
/// Sets the Bitcoin network used.
333344
pub fn set_network(&self, network: Network) {
334345
self.inner.write().unwrap().set_network(network);
@@ -377,10 +388,15 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
377388
let bdk_data_dir = format!("{}/bdk", config.storage_dir_path);
378389
fs::create_dir_all(bdk_data_dir.clone()).map_err(|_| BuildError::StoragePathAccessFailed)?;
379390

391+
let log_dir = match &config.log_dir_path {
392+
Some(log_dir) => String::from(log_dir),
393+
None => config.storage_dir_path.clone() + "/logs",
394+
};
395+
380396
// Initialize the Logger
381397
let log_file_path = format!(
382-
"{}/logs/ldk_node_{}.log",
383-
config.storage_dir_path,
398+
"{}/ldk_node_{}.log",
399+
log_dir,
384400
chrono::offset::Local::now().format("%Y_%m_%d")
385401
);
386402
let logger = Arc::new(

src/lib.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,26 @@ impl Writeable for UserOnionMessageContents {
219219
///
220220
/// ### Defaults
221221
///
222-
/// | Parameter | Value |
223-
/// |----------------------------------------|------------------|
224-
/// | `storage_dir_path` | /tmp/ldk_node/ |
225-
/// | `network` | Bitcoin |
226-
/// | `listening_address` | None |
227-
/// | `default_cltv_expiry_delta` | 144 |
228-
/// | `onchain_wallet_sync_interval_secs` | 80 |
229-
/// | `wallet_sync_interval_secs` | 30 |
230-
/// | `fee_rate_cache_update_interval_secs` | 600 |
231-
/// | `trusted_peers_0conf` | [] |
232-
/// | `log_level` | Debug |
222+
/// | Parameter | Value |
223+
/// |----------------------------------------|--------------------|
224+
/// | `storage_dir_path` | /tmp/ldk_node/ |
225+
/// | `log_dir_path` | None |
226+
/// | `network` | Bitcoin |
227+
/// | `listening_address` | None |
228+
/// | `default_cltv_expiry_delta` | 144 |
229+
/// | `onchain_wallet_sync_interval_secs` | 80 |
230+
/// | `wallet_sync_interval_secs` | 30 |
231+
/// | `fee_rate_cache_update_interval_secs` | 600 |
232+
/// | `trusted_peers_0conf` | [] |
233+
/// | `log_level` | Debug |
233234
///
234235
pub struct Config {
235236
/// The path where the underlying LDK and BDK persist their data.
236237
pub storage_dir_path: String,
238+
/// The path where logs are stored.
239+
///
240+
/// If set to `None`, logs can be found in the `logs` subdirectory in [`Config::storage_dir_path`].
241+
pub log_dir_path: Option<String>,
237242
/// The used Bitcoin network.
238243
pub network: Network,
239244
/// The IP address and TCP port the node will listen on.
@@ -268,6 +273,7 @@ impl Default for Config {
268273
fn default() -> Self {
269274
Self {
270275
storage_dir_path: DEFAULT_STORAGE_DIR_PATH.to_string(),
276+
log_dir_path: None,
271277
network: DEFAULT_NETWORK,
272278
listening_address: None,
273279
default_cltv_expiry_delta: DEFAULT_CLTV_EXPIRY_DELTA,

0 commit comments

Comments
 (0)