@@ -18,6 +18,7 @@ mod ffi {
18
18
19
19
extern "Rust" {
20
20
fn start ( pairing_file : String , log_path : String ) -> Result < ( ) , Errors > ;
21
+ fn startWithLogger ( pairing_file : String , log_path : String , is_console_logging_enabled : bool ) -> Result < ( ) , Errors > ;
21
22
fn target_minimuxer_address ( ) ;
22
23
}
23
24
}
@@ -257,9 +258,13 @@ pub static STARTED: AtomicBool = AtomicBool::new(false);
257
258
pub static STARTED : AtomicBool = AtomicBool :: new ( true ) ; // minimuxer won't start in tests
258
259
259
260
/// Starts the muxer and heartbeat client
260
- /// # Arguments
261
+ /// # Arguments\
261
262
/// Pairing file contents as a string and log path as a string
262
263
pub fn start ( pairing_file : String , log_path : String ) -> crate :: Res < ( ) > {
264
+ startWithLogger ( pairing_file, log_path, true ) // logging is enabled by default as before
265
+ }
266
+
267
+ pub fn startWithLogger ( pairing_file : String , log_path : String , is_console_logging_enabled : bool ) -> crate :: Res < ( ) > {
263
268
use fern:: Dispatch ;
264
269
use log:: LevelFilter ;
265
270
@@ -272,7 +277,7 @@ pub fn start(pairing_file: String, log_path: String) -> crate::Res<()> {
272
277
}
273
278
274
279
// the logger failing to initialize isn't a problem since it will only fail if it has already been initialized
275
- if Dispatch :: new ( )
280
+ let mut logger = Dispatch :: new ( )
276
281
. format ( |out, message, record| {
277
282
out. finish ( format_args ! (
278
283
"{} [{}] {}: {}" ,
@@ -281,9 +286,11 @@ pub fn start(pairing_file: String, log_path: String) -> crate::Res<()> {
281
286
record. target( ) ,
282
287
message
283
288
) )
284
- } )
285
- . chain (
286
- // stdout
289
+ } ) ;
290
+
291
+ // conditionally enable stdout logging only if requested
292
+ if is_console_logging_enabled {
293
+ logger = logger. chain (
287
294
Dispatch :: new ( )
288
295
. level ( LevelFilter :: Trace )
289
296
. level_for ( "plist_plus" , LevelFilter :: Off ) // plist_plus spams logs
@@ -295,17 +302,20 @@ pub fn start(pairing_file: String, log_path: String) -> crate::Res<()> {
295
302
. level_for ( "hyper" , LevelFilter :: Off )
296
303
. level_for ( "tracing" , LevelFilter :: Off ) // maybe we shouldn't do this?
297
304
. chain ( std:: io:: stdout ( ) ) ,
298
- )
299
- . chain (
300
- // minimuxer.log
301
- Dispatch :: new ( )
302
- . level ( LevelFilter :: Off )
303
- . level_for ( "minimuxer" , LevelFilter :: Info )
304
- . level_for ( "rusty_libimobiledevice" , LevelFilter :: Error )
305
- . chain ( File :: create ( & log_path) . unwrap ( ) ) ,
306
- )
307
- . apply ( )
308
- . is_ok ( )
305
+ ) ;
306
+ }
307
+
308
+ logger = logger. chain (
309
+ // minimuxer.log
310
+ Dispatch :: new ( )
311
+ . level ( LevelFilter :: Off )
312
+ . level_for ( "minimuxer" , LevelFilter :: Info )
313
+ . level_for ( "rusty_libimobiledevice" , LevelFilter :: Error )
314
+ . chain ( File :: create ( & log_path) . unwrap ( ) ) ,
315
+ ) ;
316
+
317
+ // apply logger
318
+ if logger. apply ( ) . is_ok ( )
309
319
{
310
320
info ! ( "Logger initialized!!" ) ;
311
321
}
0 commit comments