@@ -43,7 +43,7 @@ use crate::routing::scoring::{ChannelUsage, ScoreUpdate, ScoreLookUp};
43
43
use crate :: sync:: RwLock ;
44
44
use crate :: util:: config:: UserConfig ;
45
45
use crate :: util:: test_channel_signer:: { TestChannelSigner , EnforcementState } ;
46
- use crate :: util:: logger:: { Logger , Level , Record } ;
46
+ use crate :: util:: logger:: { Logger , Record } ;
47
47
use crate :: util:: ser:: { Readable , ReadableArgs , Writer , Writeable } ;
48
48
use crate :: util:: persist:: KVStore ;
49
49
@@ -1117,7 +1117,6 @@ impl events::MessageSendEventsProvider for TestRoutingMessageHandler {
1117
1117
}
1118
1118
1119
1119
pub struct TestLogger {
1120
- level : Level ,
1121
1120
pub ( crate ) id : String ,
1122
1121
pub lines : Mutex < HashMap < ( & ' static str , String ) , usize > > ,
1123
1122
pub context : Mutex < HashMap < ( & ' static str , Option < PublicKey > , Option < ChannelId > ) , usize > > ,
@@ -1129,15 +1128,11 @@ impl TestLogger {
1129
1128
}
1130
1129
pub fn with_id ( id : String ) -> TestLogger {
1131
1130
TestLogger {
1132
- level : Level :: Trace ,
1133
1131
id,
1134
1132
lines : Mutex :: new ( new_hash_map ( ) ) ,
1135
1133
context : Mutex :: new ( new_hash_map ( ) ) ,
1136
1134
}
1137
1135
}
1138
- pub fn enable ( & mut self , level : Level ) {
1139
- self . level = level;
1140
- }
1141
1136
pub fn assert_log ( & self , module : & str , line : String , count : usize ) {
1142
1137
let log_entries = self . lines . lock ( ) . unwrap ( ) ;
1143
1138
assert_eq ! ( log_entries. get( & ( module, line) ) , Some ( & count) ) ;
@@ -1179,11 +1174,24 @@ impl TestLogger {
1179
1174
1180
1175
impl Logger for TestLogger {
1181
1176
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) ;
1187
1195
}
1188
1196
}
1189
1197
}
0 commit comments