@@ -16,26 +16,30 @@ pub(crate) struct FilesystemLogger {
1616}
1717
1818impl 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 ( ) {
2125 fs:: create_dir_all ( parent_dir) . expect ( "Failed to create log parent directory" ) ;
2226
2327 // make sure the file exists, so that the symlink has something to point to.
2428 fs:: OpenOptions :: new ( )
2529 . create ( true )
2630 . append ( true )
27- . open ( file_path . clone ( ) )
31+ . open ( log_file_path . clone ( ) )
2832 . map_err ( |_| ( ) ) ?;
2933
3034 // Create a symlink to the current log file, with prior cleanup
3135 let log_file_symlink = parent_dir. join ( "ldk_node_latest.log" ) ;
3236 if log_file_symlink. as_path ( ) . exists ( ) && log_file_symlink. as_path ( ) . is_symlink ( ) {
3337 fs:: remove_file ( & log_file_symlink) . map_err ( |_| ( ) ) ?;
3438 }
35- symlink ( & file_path , & log_file_symlink) . map_err ( |_| ( ) ) ?;
39+ symlink ( & log_file_name , & log_file_symlink) . map_err ( |_| ( ) ) ?;
3640 }
3741
38- Ok ( Self { file_path, level } )
42+ Ok ( Self { file_path : log_file_path , level } )
3943 }
4044}
4145impl Logger for FilesystemLogger {
0 commit comments