File tree 3 files changed +29
-2
lines changed
3 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -417,8 +417,12 @@ impl Builder {
417
417
let config = Arc :: new ( self . config . read ( ) . unwrap ( ) . clone ( ) ) ;
418
418
419
419
// Initialize the Logger
420
- let log_file_path = format ! ( "{}/ldk_node.log" , config. storage_dir_path) ;
421
- let logger = Arc :: new ( FilesystemLogger :: new ( log_file_path, config. log_level ) ) ;
420
+ let log_file_path = format ! (
421
+ "{}/logs/ldk_node_{}.log" ,
422
+ config. storage_dir_path,
423
+ chrono:: offset:: Local :: now( ) . format( "%Y_%m_%d" )
424
+ ) ;
425
+ let logger = Arc :: new ( FilesystemLogger :: new ( log_file_path. clone ( ) , config. log_level ) ) ;
422
426
423
427
// Initialize the on-chain wallet and chain access
424
428
let seed_bytes = match & * self . entropy_source_config . read ( ) . unwrap ( ) {
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ use lightning::util::ser::Writer;
7
7
use chrono:: Utc ;
8
8
9
9
use std:: fs;
10
+ use std:: os:: unix:: fs:: symlink;
10
11
use std:: path:: Path ;
11
12
12
13
pub ( crate ) struct FilesystemLogger {
@@ -18,7 +19,26 @@ impl FilesystemLogger {
18
19
pub ( crate ) fn new ( file_path : String , level : Level ) -> Self {
19
20
if let Some ( parent_dir) = Path :: new ( & file_path) . parent ( ) {
20
21
fs:: create_dir_all ( parent_dir) . expect ( "Failed to create log parent directory" ) ;
22
+
23
+ // make sure the file exists, so that the symlink has something to point to.
24
+ fs:: OpenOptions :: new ( )
25
+ . create ( true )
26
+ . append ( true )
27
+ . open ( file_path. clone ( ) )
28
+ . expect ( "Failed to open log file" ) ;
29
+
30
+ // Create a symlink to the current log file, with prior cleanup
31
+ let log_file_symlink = parent_dir. join ( "ldk_node_latest.log" ) ;
32
+ if log_file_symlink. as_path ( ) . exists ( ) && log_file_symlink. as_path ( ) . is_symlink ( ) {
33
+ fs:: remove_file ( & log_file_symlink)
34
+ . expect ( "Failed to remove an old symlink for the log file" ) ;
35
+ }
36
+ symlink ( & file_path, & log_file_symlink) . expect ( & format ! (
37
+ "Failed to create symlink for the log file: {:?}" ,
38
+ log_file_symlink
39
+ ) ) ;
21
40
}
41
+
22
42
Self { file_path, level }
23
43
}
24
44
}
Original file line number Diff line number Diff line change @@ -310,6 +310,9 @@ fn start_stop_reinit() {
310
310
node. sync_wallets ( ) . unwrap ( ) ;
311
311
assert_eq ! ( node. onchain_balance( ) . unwrap( ) . get_spendable( ) , expected_amount. to_sat( ) ) ;
312
312
313
+ let log_file_symlink = format ! ( "{}/logs/ldk_node_latest.log" , config. storage_dir_path) ;
314
+ assert ! ( std:: path:: Path :: new( & log_file_symlink) . is_symlink( ) ) ;
315
+
313
316
node. stop ( ) . unwrap ( ) ;
314
317
assert_eq ! ( node. stop( ) , Err ( Error :: NotRunning ) ) ;
315
318
You can’t perform that action at this time.
0 commit comments