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 @@ -121,6 +121,7 @@ enum BuildError {
121
121
"IOWriteFailed",
122
122
"StoragePathAccessFailed",
123
123
"WalletSetupFailed",
124
+ "LoggerSetupFailed",
124
125
};
125
126
126
127
[Enum]
Original file line number Diff line number Diff line change @@ -84,6 +84,8 @@ pub enum BuildError {
84
84
StoragePathAccessFailed ,
85
85
/// We failed to setup the onchain wallet.
86
86
WalletSetupFailed ,
87
+ /// We failed to setup the logger.
88
+ LoggerSetupFailed ,
87
89
}
88
90
89
91
impl fmt:: Display for BuildError {
@@ -97,6 +99,7 @@ impl fmt::Display for BuildError {
97
99
Self :: IOWriteFailed => write ! ( f, "Failed to write to store." ) ,
98
100
Self :: StoragePathAccessFailed => write ! ( f, "Failed to access the given storage path." ) ,
99
101
Self :: WalletSetupFailed => write ! ( f, "Failed to setup onchain wallet." ) ,
102
+ Self :: LoggerSetupFailed => write ! ( f, "Failed to setup the logger." ) ,
100
103
}
101
104
}
102
105
}
@@ -377,7 +380,10 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
377
380
config. storage_dir_path,
378
381
chrono:: offset:: Local :: now( ) . format( "%Y_%m_%d" )
379
382
) ;
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
+ ) ;
381
387
382
388
// Initialize the on-chain wallet and chain access
383
389
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 {
16
16
}
17
17
18
18
impl FilesystemLogger {
19
- pub ( crate ) fn new ( file_path : String , level : Level ) -> Self {
19
+ pub ( crate ) fn new ( file_path : String , level : Level ) -> Result < Self , ( ) > {
20
20
if let Some ( parent_dir) = Path :: new ( & file_path) . parent ( ) {
21
21
fs:: create_dir_all ( parent_dir) . expect ( "Failed to create log parent directory" ) ;
22
22
@@ -25,21 +25,17 @@ impl FilesystemLogger {
25
25
. create ( true )
26
26
. append ( true )
27
27
. open ( file_path. clone ( ) )
28
- . expect ( "Failed to open log file" ) ;
28
+ . map_err ( |_| ( ) ) ? ;
29
29
30
30
// Create a symlink to the current log file, with prior cleanup
31
31
let log_file_symlink = parent_dir. join ( "ldk_node_latest.log" ) ;
32
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" ) ;
33
+ fs:: remove_file ( & log_file_symlink) . map_err ( |_| ( ) ) ?;
35
34
}
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 ( |_| ( ) ) ?;
40
36
}
41
37
42
- Self { file_path, level }
38
+ Ok ( Self { file_path, level } )
43
39
}
44
40
}
45
41
impl Logger for FilesystemLogger {
You can’t perform that action at this time.
0 commit comments