File tree Expand file tree Collapse file tree 3 files changed +13
-10
lines changed
Expand file tree Collapse file tree 3 files changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,7 @@ enum BuildError {
125125 "WriteFailed",
126126 "StoragePathAccessFailed",
127127 "WalletSetupFailed",
128+ "LoggerSetupFailed",
128129};
129130
130131[Enum]
Original file line number Diff line number Diff line change @@ -84,6 +84,8 @@ pub enum BuildError {
8484 StoragePathAccessFailed ,
8585 /// We failed to setup the onchain wallet.
8686 WalletSetupFailed ,
87+ /// We failed to setup the logger.
88+ LoggerSetupFailed ,
8789}
8890
8991impl fmt:: Display for BuildError {
@@ -97,6 +99,7 @@ impl fmt::Display for BuildError {
9799 Self :: WriteFailed => write ! ( f, "Failed to write to store." ) ,
98100 Self :: StoragePathAccessFailed => write ! ( f, "Failed to access the given storage path." ) ,
99101 Self :: WalletSetupFailed => write ! ( f, "Failed to setup onchain wallet." ) ,
102+ Self :: LoggerSetupFailed => write ! ( f, "Failed to setup the logger." ) ,
100103 }
101104 }
102105}
@@ -377,7 +380,10 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
377380 config. storage_dir_path,
378381 chrono:: offset:: Local :: now( ) . format( "%Y_%m_%d" )
379382 ) ;
380- let logger = Arc :: new ( FilesystemLogger :: new ( log_file_path. clone ( ) , config. log_level ) ) ;
383+ let logger = Arc :: new (
384+ FilesystemLogger :: new ( log_file_path. clone ( ) , config. log_level )
385+ . map_err ( |_| BuildError :: LoggerSetupFailed ) ?,
386+ ) ;
381387
382388 // Initialize the on-chain wallet and chain access
383389 let seed_bytes = match entropy_source_config {
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ pub(crate) struct FilesystemLogger {
1616}
1717
1818impl FilesystemLogger {
19- pub ( crate ) fn new ( file_path : String , level : Level ) -> Self {
19+ pub ( crate ) fn new ( file_path : String , level : Level ) -> Result < Self , ( ) > {
2020 if let Some ( parent_dir) = Path :: new ( & file_path) . parent ( ) {
2121 fs:: create_dir_all ( parent_dir) . expect ( "Failed to create log parent directory" ) ;
2222
@@ -25,21 +25,17 @@ impl FilesystemLogger {
2525 . create ( true )
2626 . append ( true )
2727 . open ( file_path. clone ( ) )
28- . expect ( "Failed to open log file" ) ;
28+ . map_err ( |_| ( ) ) ? ;
2929
3030 // Create a symlink to the current log file, with prior cleanup
3131 let log_file_symlink = parent_dir. join ( "ldk_node_latest.log" ) ;
3232 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" ) ;
33+ fs:: remove_file ( & log_file_symlink) . map_err ( |_| ( ) ) ?;
3534 }
36- symlink ( & file_path, & log_file_symlink) . expect ( & format ! (
37- "Failed to create symlink for the log file: {:?}" ,
38- log_file_symlink
39- ) ) ;
35+ symlink ( & file_path, & log_file_symlink) . map_err ( |_| ( ) ) ?;
4036 }
4137
42- Self { file_path, level }
38+ Ok ( Self { file_path, level } )
4339 }
4440}
4541impl Logger for FilesystemLogger {
You can’t perform that action at this time.
0 commit comments