Skip to content

Commit fa071fd

Browse files
committed
refactor: replace log directory path to log file path
1 parent dc9f840 commit fa071fd

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed

bindings/ldk_node.udl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace ldk_node {
55

66
dictionary Config {
77
string storage_dir_path;
8-
string? log_dir_path;
8+
string? log_file_path;
99
Network network;
1010
sequence<SocketAddress>? listening_addresses;
1111
NodeAlias? node_alias;

src/builder.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,9 @@ impl NodeBuilder {
298298
self
299299
}
300300

301-
/// Sets the log dir path if logs need to live separate from the storage directory path.
302-
pub fn set_log_dir_path(&mut self, log_dir_path: String) -> &mut Self {
303-
self.config.log_dir_path = Some(log_dir_path);
301+
/// Sets the log file path if the log file needs to live separate from the storage directory path.
302+
pub fn set_log_file_path(&mut self, log_dir_path: String) -> &mut Self {
303+
self.config.log_file_path = Some(log_dir_path);
304304
self
305305
}
306306

@@ -611,8 +611,8 @@ impl ArcedNodeBuilder {
611611
}
612612

613613
/// Sets the log dir path if logs need to live separate from the storage directory path.
614-
pub fn set_log_dir_path(&self, log_dir_path: String) {
615-
self.inner.write().unwrap().set_log_dir_path(log_dir_path);
614+
pub fn set_log_file_path(&self, log_file_path: String) {
615+
self.inner.write().unwrap().set_log_file_path(log_file_path);
616616
}
617617

618618
/// Sets the Bitcoin network used.
@@ -1234,13 +1234,13 @@ fn build_with_store_internal(
12341234
/// Sets up the node logger, creating a new log file if it does not exist, or utilizing
12351235
/// the existing log file.
12361236
fn setup_logger(config: &Config) -> Result<Arc<FilesystemLogger>, BuildError> {
1237-
let log_dir = match &config.log_dir_path {
1237+
let log_file_path = match &config.log_file_path {
12381238
Some(log_dir) => String::from(log_dir),
1239-
None => config.storage_dir_path.clone(),
1239+
None => format!("{}/{}", config.storage_dir_path.clone(), "ldk_node.log"),
12401240
};
12411241

12421242
Ok(Arc::new(
1243-
FilesystemLogger::new(log_dir, config.log_level)
1243+
FilesystemLogger::new(log_file_path, config.log_level)
12441244
.map_err(|_| BuildError::LoggerSetupFailed)?,
12451245
))
12461246
}

src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ pub struct Config {
105105
pub storage_dir_path: String,
106106
/// The path where logs are stored.
107107
///
108-
/// If set to `None`, logs can be found in the `logs` subdirectory in [`Config::storage_dir_path`].
109-
pub log_dir_path: Option<String>,
108+
/// If set to `None`, logs can be found in [`Config::storage_dir_path`] directory.
109+
pub log_file_path: Option<String>,
110110
/// The used Bitcoin network.
111111
pub network: Network,
112112
/// The addresses on which the node will listen for incoming connections.
@@ -167,7 +167,7 @@ impl Default for Config {
167167
fn default() -> Self {
168168
Self {
169169
storage_dir_path: DEFAULT_STORAGE_DIR_PATH.to_string(),
170-
log_dir_path: None,
170+
log_file_path: None,
171171
network: DEFAULT_NETWORK,
172172
listening_addresses: None,
173173
trusted_peers_0conf: Vec::new(),

src/logger.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,16 @@ pub(crate) struct FilesystemLogger {
2222
}
2323

2424
impl FilesystemLogger {
25-
/// Creates a new filesystem logger given the path to the log file directory and the log level.
26-
pub(crate) fn new(log_dir: String, level: Level) -> Result<Self, ()> {
27-
let log_file_name = "ldk_node.log";
28-
let log_file_path = format!("{}/{}", log_dir, log_file_name);
29-
25+
/// Creates a new filesystem logger given the path to the log file and the log level.
26+
pub(crate) fn new(log_file_path: String, level: Level) -> Result<Self, ()> {
3027
if let Some(parent_dir) = Path::new(&log_file_path).parent() {
3128
fs::create_dir_all(parent_dir).expect("Failed to create log parent directory");
3229

3330
// make sure the file exists.
3431
fs::OpenOptions::new()
3532
.create(true)
3633
.append(true)
37-
.open(log_file_path.clone())
34+
.open(&log_file_path)
3835
.map_err(|e| eprintln!("ERROR: Failed to open log file: {}", e))?;
3936
}
4037

0 commit comments

Comments
 (0)