88#![ cfg( any( test, cln_test, vss_test) ) ]
99#![ allow( dead_code) ]
1010
11- use ldk_node:: config:: { Config , EsploraSyncConfig } ;
11+ use ldk_node:: config:: {
12+ Config , EsploraSyncConfig , DEFAULT_LOG_FILENAME , DEFAULT_LOG_LEVEL , DEFAULT_STORAGE_DIR_PATH ,
13+ } ;
1214use ldk_node:: io:: sqlite_store:: SqliteStore ;
13- use ldk_node:: logger:: LogLevel ;
15+ use ldk_node:: logger:: { LogLevel , LogWriter } ;
1416use ldk_node:: payment:: { PaymentDirection , PaymentKind , PaymentStatus } ;
1517use ldk_node:: {
1618 Builder , CustomTlvRecord , Event , LightningBalance , Node , NodeError , PendingSweepBalance ,
@@ -215,7 +217,7 @@ pub(crate) fn random_node_alias() -> Option<NodeAlias> {
215217 Some ( NodeAlias ( bytes) )
216218}
217219
218- pub ( crate ) fn random_config ( anchor_channels : bool ) -> Config {
220+ pub ( crate ) fn random_config ( anchor_channels : bool ) -> TestConfig {
219221 let mut config = Config :: default ( ) ;
220222
221223 if !anchor_channels {
@@ -237,7 +239,7 @@ pub(crate) fn random_config(anchor_channels: bool) -> Config {
237239 println ! ( "Setting random LDK node alias: {:?}" , alias) ;
238240 config. node_alias = alias;
239241
240- config
242+ TestConfig { node_config : config, log_writer : TestLogWriter :: default ( ) }
241243}
242244
243245#[ cfg( feature = "uniffi" ) ]
@@ -251,6 +253,34 @@ pub(crate) enum TestChainSource<'a> {
251253 BitcoindRpc ( & ' a BitcoinD ) ,
252254}
253255
256+ #[ derive( Clone ) ]
257+ pub ( crate ) enum TestLogWriter {
258+ FileWriter { file_path : String , max_log_level : LogLevel } ,
259+ LogFacade { max_log_level : LogLevel } ,
260+ Custom ( Arc < dyn LogWriter > ) ,
261+ }
262+
263+ impl Default for TestLogWriter {
264+ fn default ( ) -> Self {
265+ TestLogWriter :: FileWriter {
266+ file_path : format ! ( "{}/{}" , DEFAULT_STORAGE_DIR_PATH , DEFAULT_LOG_FILENAME ) ,
267+ max_log_level : DEFAULT_LOG_LEVEL ,
268+ }
269+ }
270+ }
271+
272+ #[ derive( Clone ) ]
273+ pub ( crate ) struct TestConfig {
274+ pub node_config : Config ,
275+ pub log_writer : TestLogWriter ,
276+ }
277+
278+ impl Default for TestConfig {
279+ fn default ( ) -> Self {
280+ Self { node_config : Config :: default ( ) , log_writer : TestLogWriter :: default ( ) }
281+ }
282+ }
283+
254284macro_rules! setup_builder {
255285 ( $builder: ident, $config: expr) => {
256286 #[ cfg( feature = "uniffi" ) ]
@@ -273,10 +303,11 @@ pub(crate) fn setup_two_nodes(
273303 println ! ( "\n == Node B ==" ) ;
274304 let mut config_b = random_config ( anchor_channels) ;
275305 if allow_0conf {
276- config_b. trusted_peers_0conf . push ( node_a. node_id ( ) ) ;
306+ config_b. node_config . trusted_peers_0conf . push ( node_a. node_id ( ) ) ;
277307 }
278308 if anchor_channels && anchors_trusted_no_reserve {
279309 config_b
310+ . node_config
280311 . anchor_channels_config
281312 . as_mut ( )
282313 . unwrap ( )
@@ -288,9 +319,9 @@ pub(crate) fn setup_two_nodes(
288319}
289320
290321pub ( crate ) fn setup_node (
291- chain_source : & TestChainSource , config : Config , seed_bytes : Option < Vec < u8 > > ,
322+ chain_source : & TestChainSource , config : TestConfig , seed_bytes : Option < Vec < u8 > > ,
292323) -> TestNode {
293- setup_builder ! ( builder, config) ;
324+ setup_builder ! ( builder, config. node_config ) ;
294325 match chain_source {
295326 TestChainSource :: Esplora ( electrsd) => {
296327 let esplora_url = format ! ( "http://{}" , electrsd. esplora_url. as_ref( ) . unwrap( ) ) ;
@@ -309,14 +340,23 @@ pub(crate) fn setup_node(
309340 } ,
310341 }
311342
312- let log_file_path = format ! ( "{}/{}" , config. storage_dir_path, "ldk_node.log" ) ;
313- builder. set_filesystem_logger ( Some ( log_file_path) , Some ( LogLevel :: Gossip ) ) ;
343+ match & config. log_writer {
344+ TestLogWriter :: FileWriter { file_path, max_log_level } => {
345+ builder. set_filesystem_logger ( Some ( file_path. clone ( ) ) , Some ( * max_log_level) ) ;
346+ } ,
347+ TestLogWriter :: LogFacade { max_log_level } => {
348+ builder. set_log_facade_logger ( Some ( * max_log_level) ) ;
349+ } ,
350+ TestLogWriter :: Custom ( custom_log_writer) => {
351+ builder. set_custom_logger ( Arc :: clone ( custom_log_writer) ) ;
352+ } ,
353+ }
314354
315355 if let Some ( seed) = seed_bytes {
316356 builder. set_entropy_seed_bytes ( seed) . unwrap ( ) ;
317357 }
318358
319- let test_sync_store = Arc :: new ( TestSyncStore :: new ( config. storage_dir_path . into ( ) ) ) ;
359+ let test_sync_store = Arc :: new ( TestSyncStore :: new ( config. node_config . storage_dir_path . into ( ) ) ) ;
320360 let node = builder. build_with_store ( test_sync_store) . unwrap ( ) ;
321361 node. start ( ) . unwrap ( ) ;
322362 assert ! ( node. status( ) . is_running) ;
0 commit comments