@@ -16,26 +16,30 @@ pub(crate) struct FilesystemLogger {
16
16
}
17
17
18
18
impl FilesystemLogger {
19
- pub ( crate ) fn new ( file_path : String , level : Level ) -> Result < Self , ( ) > {
20
- if let Some ( parent_dir) = Path :: new ( & file_path) . parent ( ) {
19
+ pub ( crate ) fn new ( log_dir : String , level : Level ) -> Result < Self , ( ) > {
20
+ let log_file_name =
21
+ format ! ( "ldk_node_{}.log" , chrono:: offset:: Local :: now( ) . format( "%Y_%m_%d" ) ) ;
22
+ let log_file_path = format ! ( "{}/{}" , log_dir, log_file_name) ;
23
+
24
+ if let Some ( parent_dir) = Path :: new ( & log_file_path) . parent ( ) {
21
25
fs:: create_dir_all ( parent_dir) . expect ( "Failed to create log parent directory" ) ;
22
26
23
27
// make sure the file exists, so that the symlink has something to point to.
24
28
fs:: OpenOptions :: new ( )
25
29
. create ( true )
26
30
. append ( true )
27
- . open ( file_path . clone ( ) )
31
+ . open ( log_file_path . clone ( ) )
28
32
. map_err ( |_| ( ) ) ?;
29
33
30
34
// Create a symlink to the current log file, with prior cleanup
31
35
let log_file_symlink = parent_dir. join ( "ldk_node_latest.log" ) ;
32
36
if log_file_symlink. as_path ( ) . exists ( ) && log_file_symlink. as_path ( ) . is_symlink ( ) {
33
37
fs:: remove_file ( & log_file_symlink) . map_err ( |_| ( ) ) ?;
34
38
}
35
- symlink ( & file_path , & log_file_symlink) . map_err ( |_| ( ) ) ?;
39
+ symlink ( & log_file_name , & log_file_symlink) . map_err ( |_| ( ) ) ?;
36
40
}
37
41
38
- Ok ( Self { file_path, level } )
42
+ Ok ( Self { file_path : log_file_path , level } )
39
43
}
40
44
}
41
45
impl Logger for FilesystemLogger {
0 commit comments