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 {
807807 static FORMATTER : RefCell <Option <Formatter >> = RefCell :: new( None ) ;
808808 }
809809
810- FORMATTER . with ( |tl_buf| {
810+ let tls_result = FORMATTER . try_with ( |tl_buf| {
811811 // It's possible for implementations to sometimes
812812 // log-while-logging (e.g. a `std::fmt` implementation logs
813813 // internally) but it's super rare. If this happens make sure we
@@ -842,6 +842,15 @@ impl Log for Logger {
842842 // Always clear the buffer afterwards
843843 formatter. clear ( ) ;
844844 } ) ;
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+ }
845854 }
846855 }
847856
You can’t perform that action at this time.
0 commit comments