Skip to content

Commit 3a31209

Browse files
committed
Change log symlink to be relative
1 parent bf0c851 commit 3a31209

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/builder.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,8 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
394394
};
395395

396396
// Initialize the Logger
397-
let log_file_path = format!(
398-
"{}/ldk_node_{}.log",
399-
log_dir,
400-
chrono::offset::Local::now().format("%Y_%m_%d")
401-
);
402397
let logger = Arc::new(
403-
FilesystemLogger::new(log_file_path.clone(), config.log_level)
398+
FilesystemLogger::new(log_dir, config.log_level)
404399
.map_err(|_| BuildError::LoggerSetupFailed)?,
405400
);
406401

src/logger.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,30 @@ pub(crate) struct FilesystemLogger {
1616
}
1717

1818
impl FilesystemLogger {
19-
pub(crate) fn new(file_path: String, level: Level) -> Result<Self, ()> {
20-
if let Some(parent_dir) = Path::new(&file_path).parent() {
19+
pub(crate) fn new(log_dir: String, level: Level) -> Result<Self, ()> {
20+
let log_file_name =
21+
format!("ldk_node_{}.log", chrono::offset::Local::now().format("%Y_%m_%d"));
22+
let log_file_path = format!("{}/{}", log_dir, log_file_name);
23+
24+
if let Some(parent_dir) = Path::new(&log_file_path).parent() {
2125
fs::create_dir_all(parent_dir).expect("Failed to create log parent directory");
2226

2327
// make sure the file exists, so that the symlink has something to point to.
2428
fs::OpenOptions::new()
2529
.create(true)
2630
.append(true)
27-
.open(file_path.clone())
31+
.open(log_file_path.clone())
2832
.map_err(|_| ())?;
2933

3034
// Create a symlink to the current log file, with prior cleanup
3135
let log_file_symlink = parent_dir.join("ldk_node_latest.log");
3236
if log_file_symlink.as_path().exists() && log_file_symlink.as_path().is_symlink() {
3337
fs::remove_file(&log_file_symlink).map_err(|_| ())?;
3438
}
35-
symlink(&file_path, &log_file_symlink).map_err(|_| ())?;
39+
symlink(&log_file_name, &log_file_symlink).map_err(|_| ())?;
3640
}
3741

38-
Ok(Self { file_path, level })
42+
Ok(Self { file_path: log_file_path, level })
3943
}
4044
}
4145
impl Logger for FilesystemLogger {

0 commit comments

Comments
 (0)