File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,5 +23,9 @@ chrono = "0.4"
2323name = " regexp_filter"
2424harness = false
2525
26+ [[test ]]
27+ name = " log-in-log"
28+ harness = false
29+
2630[features ]
2731default = [" regex" ]
Original file line number Diff line number Diff line change @@ -468,7 +468,19 @@ impl Log for Logger {
468468 }
469469
470470 FORMATTER . with ( |tl_buf| {
471- let mut tl_buf = tl_buf. borrow_mut ( ) ;
471+ // It's possible for implementations to sometimes
472+ // log-while-logging (e.g. a `std::fmt` implementation logs
473+ // internally) but it's super rare. If this happens make sure we
474+ // at least don't panic and ship some output to the screen.
475+ let mut a;
476+ let mut b = None ;
477+ let tl_buf = match tl_buf. try_borrow_mut ( ) {
478+ Ok ( f) => {
479+ a = f;
480+ & mut * a
481+ }
482+ Err ( _) => & mut b,
483+ } ;
472484
473485 // Check the buffer style. If it's different from the logger's
474486 // style then drop the buffer and recreate it.
Original file line number Diff line number Diff line change 1+ #[ macro_use] extern crate log;
2+ extern crate env_logger;
3+
4+ use std:: process;
5+ use std:: fmt;
6+ use std:: env;
7+ use std:: str;
8+
9+ struct Foo ;
10+
11+ impl fmt:: Display for Foo {
12+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
13+ info ! ( "test" ) ;
14+ f. write_str ( "bar" )
15+ }
16+ }
17+
18+ fn main ( ) {
19+ env_logger:: init ( ) ;
20+ if env:: var ( "YOU_ARE_TESTING_NOW" ) . is_ok ( ) {
21+ return info ! ( "{}" , Foo ) ;
22+ }
23+
24+ let exe = env:: current_exe ( ) . unwrap ( ) ;
25+ let out = process:: Command :: new ( exe)
26+ . env ( "YOU_ARE_TESTING_NOW" , "1" )
27+ . env ( "RUST_LOG" , "debug" )
28+ . output ( )
29+ . unwrap_or_else ( |e| panic ! ( "Unable to start child process: {}" , e) ) ;
30+ if out. status . success ( ) {
31+ return
32+ }
33+
34+ println ! ( "test failed: {}" , out. status) ;
35+ println ! ( "--- stdout\n {}" , str :: from_utf8( & out. stdout) . unwrap( ) ) ;
36+ println ! ( "--- stderr\n {}" , str :: from_utf8( & out. stderr) . unwrap( ) ) ;
37+ process:: exit ( 1 ) ;
38+ }
You can’t perform that action at this time.
0 commit comments