File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -807,7 +807,7 @@ impl Log for Logger {
807
807
static FORMATTER : RefCell <Option <Formatter >> = RefCell :: new( None ) ;
808
808
}
809
809
810
- FORMATTER . with ( |tl_buf| {
810
+ let tls_result = FORMATTER . try_with ( |tl_buf| {
811
811
// It's possible for implementations to sometimes
812
812
// log-while-logging (e.g. a `std::fmt` implementation logs
813
813
// internally) but it's super rare. If this happens make sure we
@@ -842,6 +842,15 @@ impl Log for Logger {
842
842
// Always clear the buffer afterwards
843
843
formatter. clear ( ) ;
844
844
} ) ;
845
+
846
+ if tls_result. is_err ( ) {
847
+ // The thread-local storage was not available (because its
848
+ // destructor has already run). Create a new single-use
849
+ // Formatter on the stack for this call.
850
+ let mut formatter = Formatter :: new ( & self . writer ) ;
851
+ let _ = ( self . format ) ( & mut formatter, record)
852
+ . and_then ( |_| formatter. print ( & self . writer ) ) ;
853
+ }
845
854
}
846
855
}
847
856
You can’t perform that action at this time.
0 commit comments