Skip to content

Commit

Permalink
Change log symlink to be relative
Browse files Browse the repository at this point in the history
  • Loading branch information
orbitalturtle committed Jun 27, 2023
1 parent 7f9dcf8 commit aea51c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 1 addition & 6 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,8 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
};

// Initialize the Logger
let log_file_path = format!(
"{}/ldk_node_{}.log",
log_dir,
chrono::offset::Local::now().format("%Y_%m_%d")
);
let logger = Arc::new(
FilesystemLogger::new(log_file_path.clone(), config.log_level)
FilesystemLogger::new(log_dir, config.log_level)
.map_err(|_| BuildError::LoggerSetupFailed)?,
);

Expand Down
8 changes: 6 additions & 2 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,25 @@ pub(crate) struct FilesystemLogger {
impl FilesystemLogger {
pub(crate) fn new(file_path: String, level: Level) -> Result<Self, ()> {
if let Some(parent_dir) = Path::new(&file_path).parent() {
let log_file_name =
format!("ldk_node_{}.log", chrono::offset::Local::now().format("%Y_%m_%d"));
let log_file_path = format!("{}/{}", file_path, log_file_name);

fs::create_dir_all(parent_dir).expect("Failed to create log parent directory");

// make sure the file exists, so that the symlink has something to point to.
fs::OpenOptions::new()
.create(true)
.append(true)
.open(file_path.clone())
.open(log_file_path.clone())
.map_err(|_| ())?;

// Create a symlink to the current log file, with prior cleanup
let log_file_symlink = parent_dir.join("ldk_node_latest.log");
if log_file_symlink.as_path().exists() && log_file_symlink.as_path().is_symlink() {
fs::remove_file(&log_file_symlink).map_err(|_| ())?;
}
symlink(&file_path, &log_file_symlink).map_err(|_| ())?;
symlink(&log_file_name, &log_file_symlink).map_err(|_| ())?;
}

Ok(Self { file_path, level })
Expand Down

0 comments on commit aea51c5

Please sign in to comment.