@@ -55,12 +55,15 @@ use crate::util::config::UserConfig;
5555use crate :: util:: dyn_signer:: {
5656 DynKeysInterface , DynKeysInterfaceTrait , DynPhantomKeysInterface , DynSigner ,
5757} ;
58+ use crate :: util:: logger:: LoggerScope ;
5859use crate :: util:: logger:: { Logger , Record } ;
5960#[ cfg( feature = "std" ) ]
6061use crate :: util:: mut_global:: MutGlobal ;
6162use crate :: util:: persist:: { KVStore , KVStoreSync , MonitorName } ;
6263use crate :: util:: ser:: { Readable , ReadableArgs , Writeable , Writer } ;
6364use crate :: util:: test_channel_signer:: { EnforcementState , TestChannelSigner } ;
65+ #[ cfg( feature = "std" ) ]
66+ use std:: cell:: RefCell ;
6467
6568use bitcoin:: amount:: Amount ;
6669use bitcoin:: block:: Block ;
@@ -1759,6 +1762,26 @@ impl Logger for TestLogger {
17591762 }
17601763}
17611764
1765+ #[ cfg( feature = "std" ) ]
1766+ thread_local ! {
1767+ pub ( crate ) static THREAD_LOG_SCOPE : RefCell <Option <LoggerScope <' static >>> = RefCell :: new( None ) ;
1768+ }
1769+
1770+ /// Sets up a logging scope for the current thread with the given span name. This is useful to split up a long (test) function
1771+ /// into multiple scopes for easier log analysis.
1772+ #[ macro_export]
1773+ macro_rules! test_scope {
1774+ ( $span: expr) => {
1775+ #[ cfg( feature = "std" ) ]
1776+ crate :: util:: test_utils:: THREAD_LOG_SCOPE . with( |cell| {
1777+ // Drop old scope if it exists.
1778+ let _ = cell. borrow_mut( ) . take( ) ;
1779+ // Create new scope.
1780+ * cell. borrow_mut( ) = Some ( crate :: util:: logger:: LoggerScope :: new( $span) ) ;
1781+ } ) ;
1782+ } ;
1783+ }
1784+
17621785pub struct TestNodeSigner {
17631786 node_secret : SecretKey ,
17641787}
0 commit comments