Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert: removes date from & symlink to log files #394

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,10 +1231,12 @@ 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),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github won't comment on the line below this, but let's drop the {storage_path_dir}/logs folder now that we'll only have one log file. Rather, let's just default to {storage_path_dir}/ldk_node.log.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This variable names should be adjusted to reflect it's now a file path, not the dir path anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for this. I'll address in another PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries at all, let's just include a fixup commit in whatever logging-related PR you open next!

None => config.storage_dir_path.clone() + "/logs",
None => config.storage_dir_path.clone(),
};

Ok(Arc::new(
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");
enigbe marked this conversation as resolved.
Show resolved Hide resolved

// 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!("{}/ldk_node.log", config.clone().storage_dir_path);
enigbe marked this conversation as resolved.
Show resolved Hide resolved
assert!(std::path::Path::new(&log_file).exists());

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