@@ -43,7 +43,7 @@ use crate::routing::scoring::{ChannelUsage, ScoreUpdate, ScoreLookUp};
4343use crate :: sync:: RwLock ;
4444use crate :: util:: config:: UserConfig ;
4545use crate :: util:: test_channel_signer:: { TestChannelSigner , EnforcementState } ;
46- use crate :: util:: logger:: { Logger , Level , Record } ;
46+ use crate :: util:: logger:: { Logger , Record } ;
4747use crate :: util:: ser:: { Readable , ReadableArgs , Writer , Writeable } ;
4848use crate :: util:: persist:: KVStore ;
4949
@@ -1117,7 +1117,6 @@ impl events::MessageSendEventsProvider for TestRoutingMessageHandler {
11171117}
11181118
11191119pub struct TestLogger {
1120- level : Level ,
11211120 pub ( crate ) id : String ,
11221121 pub lines : Mutex < HashMap < ( & ' static str , String ) , usize > > ,
11231122 pub context : Mutex < HashMap < ( & ' static str , Option < PublicKey > , Option < ChannelId > ) , usize > > ,
@@ -1129,15 +1128,11 @@ impl TestLogger {
11291128 }
11301129 pub fn with_id ( id : String ) -> TestLogger {
11311130 TestLogger {
1132- level : Level :: Trace ,
11331131 id,
11341132 lines : Mutex :: new ( new_hash_map ( ) ) ,
11351133 context : Mutex :: new ( new_hash_map ( ) ) ,
11361134 }
11371135 }
1138- pub fn enable ( & mut self , level : Level ) {
1139- self . level = level;
1140- }
11411136 pub fn assert_log ( & self , module : & str , line : String , count : usize ) {
11421137 let log_entries = self . lines . lock ( ) . unwrap ( ) ;
11431138 assert_eq ! ( log_entries. get( & ( module, line) ) , Some ( & count) ) ;
@@ -1179,11 +1174,24 @@ impl TestLogger {
11791174
11801175impl Logger for TestLogger {
11811176 fn log ( & self , record : Record ) {
1182- * self . lines . lock ( ) . unwrap ( ) . entry ( ( record. module_path , format ! ( "{}" , record. args) ) ) . or_insert ( 0 ) += 1 ;
1183- * self . context . lock ( ) . unwrap ( ) . entry ( ( record. module_path , record. peer_id , record. channel_id ) ) . or_insert ( 0 ) += 1 ;
1184- if record. level >= self . level {
1185- let pfx = format ! ( "{} {} [{}:{}]" , self . id, record. level. to_string( ) , record. module_path, record. line) ;
1186- println ! ( "{:<55}{}" , pfx, record. args) ;
1177+ let s = format ! ( "{:<55} {}" ,
1178+ format_args!( "{} {} [{}:{}]" , self . id, record. level. to_string( ) , record. module_path, record. line) ,
1179+ record. args
1180+ ) ;
1181+ #[ cfg( ldk_bench) ] {
1182+ // When benchmarking, we don't actually want to print logs, but we do want to format
1183+ // them. To make sure LLVM doesn't skip the above entirely we push it through a
1184+ // volitile read. This may not be super fast, but it shouldn't be worse than anything a
1185+ // user actually does with a log
1186+ let s_bytes = s. as_bytes ( ) ;
1187+ for i in 0 ..s. len ( ) {
1188+ let _ = unsafe { core:: ptr:: read_volatile ( & s_bytes[ i] ) } ;
1189+ }
1190+ }
1191+ #[ cfg( not( ldk_bench) ) ] {
1192+ * self . lines . lock ( ) . unwrap ( ) . entry ( ( record. module_path , format ! ( "{}" , record. args) ) ) . or_insert ( 0 ) += 1 ;
1193+ * self . context . lock ( ) . unwrap ( ) . entry ( ( record. module_path , record. peer_id , record. channel_id ) ) . or_insert ( 0 ) += 1 ;
1194+ println ! ( "{}" , s) ;
11871195 }
11881196 }
11891197}
0 commit comments