Skip to content

Commit

Permalink
revert: removes date from & symlink to log files (PR #116)
Browse files Browse the repository at this point in the history
This commit reverts the changes introduce by PR #116 which added the
date to log files when the node is started & a symlink to track the latest log
file. This reversal is necessary to simplify the work required to integrate with
OS-level log tools.
  • Loading branch information
enigbe committed Oct 31, 2024
1 parent 9e00f35 commit 24cf565
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,8 @@ fn build_with_store_internal(
})
}

/// Sets up the node logger, creating a new log file if it does not exist, or utilizing
/// the existing log file.
fn setup_logger(config: &Config) -> Result<Arc<FilesystemLogger>, BuildError> {
let log_dir = match &config.log_dir_path {
Some(log_dir) => String::from(log_dir),
Expand Down
21 changes: 3 additions & 18 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ use chrono::Utc;

use std::fs;
use std::io::Write;
#[cfg(not(target_os = "windows"))]
use std::os::unix::fs::symlink;
use std::path::Path;

pub(crate) struct FilesystemLogger {
Expand All @@ -24,33 +22,20 @@ pub(crate) struct FilesystemLogger {
}

impl FilesystemLogger {
/// Creates a new filesystem logger given the path to the log file directory and the log level.
pub(crate) fn new(log_dir: String, level: Level) -> Result<Self, ()> {
let log_file_name =
format!("ldk_node_{}.log", chrono::offset::Local::now().format("%Y_%m_%d"));
let log_file_name = "ldk_node.log";
let log_file_path = format!("{}/{}", log_dir, log_file_name);

if let Some(parent_dir) = Path::new(&log_file_path).parent() {
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.
// make sure the file exists.
fs::OpenOptions::new()
.create(true)
.append(true)
.open(log_file_path.clone())
.map_err(|e| eprintln!("ERROR: Failed to open log file: {}", e))?;

#[cfg(not(target_os = "windows"))]
{
// 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().is_symlink() {
fs::remove_file(&log_file_symlink).map_err(|e| {
eprintln!("ERROR: Failed to remove log file symlink: {}", e)
})?;
}
symlink(&log_file_name, &log_file_symlink)
.map_err(|e| eprintln!("ERROR: Failed to create log file symlink: {}", e))?;
}
}

Ok(Self { file_path: log_file_path, level })
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ fn start_stop_reinit() {
node.sync_wallets().unwrap();
assert_eq!(node.list_balances().spendable_onchain_balance_sats, expected_amount.to_sat());

let log_file_symlink = format!("{}/logs/ldk_node_latest.log", config.clone().storage_dir_path);
assert!(std::path::Path::new(&log_file_symlink).is_symlink());
let log_file = format!("{}/logs/ldk_node.log", config.clone().storage_dir_path);
assert!(std::path::Path::new(&log_file).exists());

node.stop().unwrap();
assert_eq!(node.stop(), Err(NodeError::NotRunning));
Expand Down

0 comments on commit 24cf565

Please sign in to comment.