6
6
// accordance with one or both of these licenses.
7
7
8
8
use crate :: chain:: { ChainSource , DEFAULT_ESPLORA_SERVER_URL } ;
9
- use crate :: config:: { default_user_config, Config , EsploraSyncConfig , WALLET_KEYS_SEED_LEN } ;
9
+ use crate :: config:: {
10
+ default_user_config, Config , EsploraSyncConfig , FilesystemLoggerConfig , WALLET_KEYS_SEED_LEN ,
11
+ } ;
10
12
11
13
use crate :: connection:: ConnectionManager ;
12
14
use crate :: event:: EventQueue ;
@@ -16,7 +18,7 @@ use crate::io::sqlite_store::SqliteStore;
16
18
use crate :: io:: utils:: { read_node_metrics, write_node_metrics} ;
17
19
use crate :: io:: vss_store:: VssStore ;
18
20
use crate :: liquidity:: LiquiditySource ;
19
- use crate :: logger:: { log_error, log_info, FilesystemLogger , Logger } ;
21
+ use crate :: logger:: { log_error, log_info, LdkLogger , Logger } ;
20
22
use crate :: message_handler:: NodeCustomMessageHandler ;
21
23
use crate :: payment:: store:: PaymentStore ;
22
24
use crate :: peer_store:: PeerStore ;
@@ -27,8 +29,8 @@ use crate::types::{
27
29
} ;
28
30
use crate :: wallet:: persist:: KVStoreWalletPersister ;
29
31
use crate :: wallet:: Wallet ;
32
+ use crate :: Node ;
30
33
use crate :: { io, NodeMetrics } ;
31
- use crate :: { LogLevel , Node } ;
32
34
33
35
use lightning:: chain:: { chainmonitor, BestBlock , Watch } ;
34
36
use lightning:: io:: Cursor ;
@@ -106,6 +108,17 @@ impl Default for LiquiditySourceConfig {
106
108
}
107
109
}
108
110
111
+ #[ derive( Debug ) ]
112
+ enum LogWriterConfig {
113
+ File ( FilesystemLoggerConfig ) ,
114
+ }
115
+
116
+ impl Default for LogWriterConfig {
117
+ fn default ( ) -> Self {
118
+ Self :: File ( FilesystemLoggerConfig :: default ( ) )
119
+ }
120
+ }
121
+
109
122
/// An error encountered during building a [`Node`].
110
123
///
111
124
/// [`Node`]: crate::Node
@@ -182,6 +195,7 @@ pub struct NodeBuilder {
182
195
chain_data_source_config : Option < ChainDataSourceConfig > ,
183
196
gossip_source_config : Option < GossipSourceConfig > ,
184
197
liquidity_source_config : Option < LiquiditySourceConfig > ,
198
+ log_writer_config : Option < LogWriterConfig > ,
185
199
}
186
200
187
201
impl NodeBuilder {
@@ -197,12 +211,14 @@ impl NodeBuilder {
197
211
let chain_data_source_config = None ;
198
212
let gossip_source_config = None ;
199
213
let liquidity_source_config = None ;
214
+ let log_writer_config = None ;
200
215
Self {
201
216
config,
202
217
entropy_source_config,
203
218
chain_data_source_config,
204
219
gossip_source_config,
205
220
liquidity_source_config,
221
+ log_writer_config,
206
222
}
207
223
}
208
224
@@ -298,9 +314,9 @@ impl NodeBuilder {
298
314
self
299
315
}
300
316
301
- /// Sets the log file path if the log file needs to live separate from the storage directory path .
302
- pub fn set_log_file_path ( & mut self , log_dir_path : String ) -> & mut Self {
303
- self . config . log_file_path = Some ( log_dir_path ) ;
317
+ /// Configures the [`Node`] instance to write logs to the filesystem .
318
+ pub fn set_filesystem_logger ( & mut self , fs_config : FilesystemLoggerConfig ) -> & mut Self {
319
+ self . log_writer_config = Some ( LogWriterConfig :: File ( fs_config ) ) ;
304
320
self
305
321
}
306
322
@@ -333,12 +349,6 @@ impl NodeBuilder {
333
349
Ok ( self )
334
350
}
335
351
336
- /// Sets the level at which [`Node`] will log messages.
337
- pub fn set_log_level ( & mut self , level : LogLevel ) -> & mut Self {
338
- self . config . log_level = level;
339
- self
340
- }
341
-
342
352
/// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options
343
353
/// previously configured.
344
354
pub fn build ( & self ) -> Result < Node , BuildError > {
@@ -391,7 +401,10 @@ impl NodeBuilder {
391
401
) -> Result < Node , BuildError > {
392
402
use bitcoin:: key:: Secp256k1 ;
393
403
394
- let logger = setup_logger ( & self . config ) ?;
404
+ let writer = LogWriterConfig :: default ( ) ;
405
+ let log_writer_config =
406
+ if let Some ( config) = & self . log_writer_config { config } else { & writer } ;
407
+ let logger = setup_logger ( & log_writer_config) ?;
395
408
396
409
let seed_bytes = seed_bytes_from_config (
397
410
& self . config ,
@@ -456,7 +469,10 @@ impl NodeBuilder {
456
469
pub fn build_with_vss_store_and_header_provider (
457
470
& self , vss_url : String , store_id : String , header_provider : Arc < dyn VssHeaderProvider > ,
458
471
) -> Result < Node , BuildError > {
459
- let logger = setup_logger ( & self . config ) ?;
472
+ let writer = LogWriterConfig :: default ( ) ;
473
+ let log_writer_config =
474
+ if let Some ( config) = & self . log_writer_config { config } else { & writer } ;
475
+ let logger = setup_logger ( & log_writer_config) ?;
460
476
461
477
let seed_bytes = seed_bytes_from_config (
462
478
& self . config ,
@@ -488,7 +504,11 @@ impl NodeBuilder {
488
504
489
505
/// Builds a [`Node`] instance according to the options previously configured.
490
506
pub fn build_with_store ( & self , kv_store : Arc < DynStore > ) -> Result < Node , BuildError > {
491
- let logger = setup_logger ( & self . config ) ?;
507
+ let writer = LogWriterConfig :: default ( ) ;
508
+ let log_writer_config =
509
+ if let Some ( config) = & self . log_writer_config { config } else { & writer } ;
510
+ let logger = setup_logger ( & log_writer_config) ?;
511
+
492
512
let seed_bytes = seed_bytes_from_config (
493
513
& self . config ,
494
514
self . entropy_source_config . as_ref ( ) ,
@@ -610,9 +630,9 @@ impl ArcedNodeBuilder {
610
630
self . inner . write ( ) . unwrap ( ) . set_storage_dir_path ( storage_dir_path) ;
611
631
}
612
632
613
- /// Sets the log file path if logs need to live separate from the storage directory path .
614
- pub fn set_log_file_path ( & self , log_file_path : String ) {
615
- self . inner . write ( ) . unwrap ( ) . set_log_file_path ( log_file_path ) ;
633
+ /// Configures the [`Node`] instance to write logs to the filesystem .
634
+ pub fn set_filesystem_logger ( & self , fs_config : FilesystemLoggerConfig ) {
635
+ self . inner . write ( ) . unwrap ( ) . set_filesystem_logger ( fs_config ) ;
616
636
}
617
637
618
638
/// Sets the Bitcoin network used.
@@ -635,11 +655,6 @@ impl ArcedNodeBuilder {
635
655
self . inner . write ( ) . unwrap ( ) . set_node_alias ( node_alias) . map ( |_| ( ) )
636
656
}
637
657
638
- /// Sets the level at which [`Node`] will log messages.
639
- pub fn set_log_level ( & self , level : LogLevel ) {
640
- self . inner . write ( ) . unwrap ( ) . set_log_level ( level) ;
641
- }
642
-
643
658
/// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options
644
659
/// previously configured.
645
660
pub fn build ( & self ) -> Result < Arc < Node > , BuildError > {
@@ -734,7 +749,7 @@ fn build_with_store_internal(
734
749
config : Arc < Config > , chain_data_source_config : Option < & ChainDataSourceConfig > ,
735
750
gossip_source_config : Option < & GossipSourceConfig > ,
736
751
liquidity_source_config : Option < & LiquiditySourceConfig > , seed_bytes : [ u8 ; 64 ] ,
737
- logger : Arc < FilesystemLogger > , kv_store : Arc < DynStore > ,
752
+ logger : Arc < Logger > , kv_store : Arc < DynStore > ,
738
753
) -> Result < Node , BuildError > {
739
754
// Initialize the status fields.
740
755
let is_listening = Arc :: new ( AtomicBool :: new ( false ) ) ;
@@ -1242,23 +1257,22 @@ fn build_with_store_internal(
1242
1257
} )
1243
1258
}
1244
1259
1245
- /// Sets up the node logger, creating a new log file if it does not exist, or utilizing
1246
- /// the existing log file.
1247
- fn setup_logger ( config : & Config ) -> Result < Arc < FilesystemLogger > , BuildError > {
1248
- let log_file_path = match & config. log_file_path {
1249
- Some ( log_dir) => String :: from ( log_dir) ,
1250
- None => format ! ( "{}/{}" , config. storage_dir_path. clone( ) , "ldk_node.log" ) ,
1251
- } ;
1260
+ /// Sets up the node logger.
1261
+ fn setup_logger ( config : & LogWriterConfig ) -> Result < Arc < Logger > , BuildError > {
1262
+ match config {
1263
+ LogWriterConfig :: File ( fs_logger_config) => {
1264
+ let log_file_path = & fs_logger_config. log_file_path ;
1252
1265
1253
- Ok ( Arc :: new (
1254
- FilesystemLogger :: new ( log_file_path, config. log_level )
1255
- . map_err ( |_| BuildError :: LoggerSetupFailed ) ?,
1256
- ) )
1266
+ Ok ( Arc :: new (
1267
+ Logger :: new_fs_writer ( log_file_path. to_string ( ) , fs_logger_config. level )
1268
+ . map_err ( |_| BuildError :: LoggerSetupFailed ) ?,
1269
+ ) )
1270
+ } ,
1271
+ }
1257
1272
}
1258
1273
1259
1274
fn seed_bytes_from_config (
1260
- config : & Config , entropy_source_config : Option < & EntropySourceConfig > ,
1261
- logger : Arc < FilesystemLogger > ,
1275
+ config : & Config , entropy_source_config : Option < & EntropySourceConfig > , logger : Arc < Logger > ,
1262
1276
) -> Result < [ u8 ; 64 ] , BuildError > {
1263
1277
match entropy_source_config {
1264
1278
Some ( EntropySourceConfig :: SeedBytes ( bytes) ) => Ok ( bytes. clone ( ) ) ,
@@ -1280,7 +1294,7 @@ fn seed_bytes_from_config(
1280
1294
}
1281
1295
1282
1296
fn derive_vss_xprv (
1283
- config : Arc < Config > , seed_bytes : & [ u8 ; 64 ] , logger : Arc < FilesystemLogger > ,
1297
+ config : Arc < Config > , seed_bytes : & [ u8 ; 64 ] , logger : Arc < Logger > ,
1284
1298
) -> Result < Xpriv , BuildError > {
1285
1299
use bitcoin:: key:: Secp256k1 ;
1286
1300
0 commit comments