-
Notifications
You must be signed in to change notification settings - Fork 103
Add the date when the node was started to the name of the logfile. #116
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
Conversation
54a39cb
to
86f32b0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, we def. should look into log rotation. While splitting by startup date ist straightforward, it doesn't protect us from hug log files in case of long-running instances.
That said, we can probably start out with this approach and look into 'proper' log rotation in the future.
86f32b0
to
e72792e
Compare
src/lib.rs
Outdated
@@ -383,8 +383,15 @@ impl Builder { | |||
let bdk_data_dir = format!("{}/bdk", config.storage_dir_path); | |||
fs::create_dir_all(bdk_data_dir.clone()).expect("Failed to create BDK data directory"); | |||
|
|||
let logs_dir = format!("{}/logs", config.storage_dir_path); | |||
fs::create_dir_all(logs_dir.clone()).expect("Failed to create logs directory"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I think this is superfluous actually, as we're creating the directory in the logger directly:
Lines 17 to 24 in 427e74c
impl FilesystemLogger { | |
pub(crate) fn new(file_path: String, level: Level) -> Self { | |
if let Some(parent_dir) = Path::new(&file_path).parent() { | |
fs::create_dir_all(parent_dir).expect("Failed to create log parent directory"); | |
} | |
Self { file_path, level } | |
} | |
} |
e72792e
to
e13fb20
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, mod nit and one comment.
Happy to land without the symlink part though, leave it up to you whether you want to include it.
src/lib.rs
Outdated
// Initialize the Logger | ||
let log_file_path = format!("{}/ldk_node.log", config.storage_dir_path); | ||
let log_file_path = format!( | ||
"{}/ldk_node_{}.log", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might also be nice to create an symlink from ldk_node_latest.log
or similar to the most-recent logfile, which would easily allow to track the latest one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of the symlink, but it looks like there is no universal cross platform API for this. https://doc.rust-lang.org/std/fs/fn.soft_link.html I don't know what platforms are supported by ldk-node. And handling multiple variants doesn't seem wroth the effort at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mh, yes, I think we can just go with with the unix variant as Windows builds might already be broken. Happy to look into it further if we get a user request for Windows, but until then we should just assume we're on some type of UNIX.
71ff89c
to
cef2e4b
Compare
src/lib.rs
Outdated
@@ -1743,7 +1756,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> { | |||
/// # use ldk_node::bitcoin::Network; | |||
/// # let mut config = Config::default(); | |||
/// # config.network = Network::Regtest; | |||
/// # config.storage_dir_path = "/tmp/ldk_node_test/".to_string(); | |||
/// # config.storage_dir_path = "/tmp/ldk_node_test_list_payments".to_string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change seems unrelated and should be removed.
src/lib.rs
Outdated
); | ||
let logger = Arc::new(FilesystemLogger::new(log_file_path.clone(), config.log_level)); | ||
let log_file_symlink = format!("{}/ldk_node.log", config.storage_dir_path); | ||
if Path::new(&log_file_symlink).exists() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make the is_symlink
check here, too, so we won't remove anything but the symlink?
cef2e4b
to
ff8c039
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good, but I'd prefer to have the symlink logic in the logger to have it one place.
Also, this needs a rebase now I'm afraid. Sorry!
src/lib.rs
Outdated
@@ -1743,7 +1764,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> { | |||
/// # use ldk_node::bitcoin::Network; | |||
/// # let mut config = Config::default(); | |||
/// # config.network = Network::Regtest; | |||
/// # config.storage_dir_path = "/tmp/ldk_node_test/".to_string(); | |||
/// # config.storage_dir_path = "/tmp/ldk_node_test".to_string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think this change is still not necessary.
src/logger.rs
Outdated
@@ -19,6 +19,12 @@ impl FilesystemLogger { | |||
if let Some(parent_dir) = Path::new(&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. | |||
fs::OpenOptions::new() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mh, can we then move the symlink logic also here? Also, lets keep all logs (including the symlink) in the logs
folder, so just have ldk_node_latest.log
in there point to the most recent one.
ff8c039
to
ba3fc5c
Compare
This makes it easier to delete old logs Create a symlink to the latest log file.
ba3fc5c
to
2f087c8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
) This commit reverts the changes introduce by PR lightningdevkit#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.
) This commit reverts the changes introduce by PR lightningdevkit#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.
) This commit reverts the changes introduce by PR lightningdevkit#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.
This makes it easier to delete old logs