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 ,
@@ -221,7 +223,7 @@ pub(crate) fn random_node_alias() -> Option<NodeAlias> {
221223 Some ( NodeAlias ( bytes) )
222224}
223225
224- pub ( crate ) fn random_config ( anchor_channels : bool ) -> Config {
226+ pub ( crate ) fn random_config ( anchor_channels : bool ) -> TestConfig {
225227 let mut config = Config :: default ( ) ;
226228
227229 if !anchor_channels {
@@ -243,7 +245,7 @@ pub(crate) fn random_config(anchor_channels: bool) -> Config {
243245 println ! ( "Setting random LDK node alias: {:?}" , alias) ;
244246 config. node_alias = alias;
245247
246- config
248+ TestConfig { node_config : config, log_writer : TestLogWriter :: default ( ) }
247249}
248250
249251#[ cfg( feature = "uniffi" ) ]
@@ -257,6 +259,34 @@ pub(crate) enum TestChainSource<'a> {
257259 BitcoindRpc ( & ' a BitcoinD ) ,
258260}
259261
262+ #[ derive( Clone ) ]
263+ pub ( crate ) enum TestLogWriter {
264+ FileWriter { file_path : String , max_log_level : LogLevel } ,
265+ LogFacade { max_log_level : LogLevel } ,
266+ Custom ( Arc < dyn LogWriter > ) ,
267+ }
268+
269+ impl Default for TestLogWriter {
270+ fn default ( ) -> Self {
271+ TestLogWriter :: FileWriter {
272+ file_path : format ! ( "{}/{}" , DEFAULT_STORAGE_DIR_PATH , DEFAULT_LOG_FILENAME ) ,
273+ max_log_level : DEFAULT_LOG_LEVEL ,
274+ }
275+ }
276+ }
277+
278+ #[ derive( Clone ) ]
279+ pub ( crate ) struct TestConfig {
280+ pub node_config : Config ,
281+ pub log_writer : TestLogWriter ,
282+ }
283+
284+ impl Default for TestConfig {
285+ fn default ( ) -> Self {
286+ Self { node_config : Config :: default ( ) , log_writer : TestLogWriter :: default ( ) }
287+ }
288+ }
289+
260290macro_rules! setup_builder {
261291 ( $builder: ident, $config: expr) => {
262292 #[ cfg( feature = "uniffi" ) ]
@@ -279,10 +309,11 @@ pub(crate) fn setup_two_nodes(
279309 println ! ( "\n == Node B ==" ) ;
280310 let mut config_b = random_config ( anchor_channels) ;
281311 if allow_0conf {
282- config_b. trusted_peers_0conf . push ( node_a. node_id ( ) ) ;
312+ config_b. node_config . trusted_peers_0conf . push ( node_a. node_id ( ) ) ;
283313 }
284314 if anchor_channels && anchors_trusted_no_reserve {
285315 config_b
316+ . node_config
286317 . anchor_channels_config
287318 . as_mut ( )
288319 . unwrap ( )
@@ -294,9 +325,9 @@ pub(crate) fn setup_two_nodes(
294325}
295326
296327pub ( crate ) fn setup_node (
297- chain_source : & TestChainSource , config : Config , seed_bytes : Option < Vec < u8 > > ,
328+ chain_source : & TestChainSource , config : TestConfig , seed_bytes : Option < Vec < u8 > > ,
298329) -> TestNode {
299- setup_builder ! ( builder, config) ;
330+ setup_builder ! ( builder, config. node_config ) ;
300331 match chain_source {
301332 TestChainSource :: Esplora ( electrsd) => {
302333 let esplora_url = format ! ( "http://{}" , electrsd. esplora_url. as_ref( ) . unwrap( ) ) ;
@@ -315,14 +346,23 @@ pub(crate) fn setup_node(
315346 } ,
316347 }
317348
318- let log_file_path = format ! ( "{}/{}" , config. storage_dir_path, "ldk_node.log" ) ;
319- builder. set_filesystem_logger ( Some ( log_file_path) , Some ( LogLevel :: Gossip ) ) ;
349+ match & config. log_writer {
350+ TestLogWriter :: FileWriter { file_path, max_log_level } => {
351+ builder. set_filesystem_logger ( Some ( file_path. clone ( ) ) , Some ( * max_log_level) ) ;
352+ } ,
353+ TestLogWriter :: LogFacade { max_log_level } => {
354+ builder. set_log_facade_logger ( Some ( * max_log_level) ) ;
355+ } ,
356+ TestLogWriter :: Custom ( custom_log_writer) => {
357+ builder. set_custom_logger ( Arc :: clone ( custom_log_writer) ) ;
358+ } ,
359+ }
320360
321361 if let Some ( seed) = seed_bytes {
322362 builder. set_entropy_seed_bytes ( seed) . unwrap ( ) ;
323363 }
324364
325- let test_sync_store = Arc :: new ( TestSyncStore :: new ( config. storage_dir_path . into ( ) ) ) ;
365+ let test_sync_store = Arc :: new ( TestSyncStore :: new ( config. node_config . storage_dir_path . into ( ) ) ) ;
326366 let node = builder. build_with_store ( test_sync_store) . unwrap ( ) ;
327367 node. start ( ) . unwrap ( ) ;
328368 assert ! ( node. status( ) . is_running) ;
0 commit comments