@@ -129,21 +129,21 @@ impl Sink for AsyncPoolSink {
129129 }
130130
131131 fn flush ( & self ) -> Result < ( ) > {
132- if crate :: IS_TEARING_DOWN . load ( Ordering :: SeqCst ) {
133- // https://github.com/SpriteOvO/spdlog-rs/issues/64
134- //
135- // If the program is tearing down, this will be the final flush. `crossbeam`
136- // uses thread-local internally, which is not supported in `atexit` callback.
137- // This can be bypassed by flushing sinks directly on the current thread, but
138- // before we do that we have to destroy the thread pool to ensure that any
139- // pending log tasks are completed.
140- self . thread_pool . destroy ( ) ;
141- self . backend . flush ( )
142- } else {
143- self . assign_task ( Task :: Flush {
144- backend : self . clone_backend ( ) ,
145- } )
146- }
132+ self . assign_task ( Task :: Flush {
133+ backend : self . clone_backend ( ) ,
134+ } )
135+ }
136+
137+ fn flush_on_exit ( & self ) -> Result < ( ) > {
138+ // https://github.com/SpriteOvO/spdlog-rs/issues/64
139+ //
140+ // If the program is tearing down, this will be the final flush. `crossbeam`
141+ // uses thread-local internally, which is not supported in `atexit` callback.
142+ // This can be bypassed by flushing sinks directly on the current thread, but
143+ // before we do that we have to destroy the thread pool to ensure that any
144+ // pending log tasks are completed.
145+ self . thread_pool . destroy ( ) ;
146+ self . backend . flush_on_exit ( )
147147 }
148148}
149149
@@ -258,14 +258,22 @@ impl Backend {
258258 result
259259 }
260260
261- fn flush ( & self ) -> Result < ( ) > {
261+ fn flush_with ( & self , with : impl Fn ( & dyn Sink ) -> Result < ( ) > ) -> Result < ( ) > {
262262 let mut result = Ok ( ( ) ) ;
263263 for sink in & self . sinks {
264- result = Error :: push_result ( result, sink . flush ( ) ) ;
264+ result = Error :: push_result ( result, with ( & * * sink ) ) ;
265265 }
266266 result
267267 }
268268
269+ fn flush ( & self ) -> Result < ( ) > {
270+ self . flush_with ( |sink| sink. flush ( ) )
271+ }
272+
273+ fn flush_on_exit ( & self ) -> Result < ( ) > {
274+ self . flush_with ( |sink| sink. flush_on_exit ( ) )
275+ }
276+
269277 fn handle_error ( & self , err : Error ) {
270278 self . prop . call_error_handler_internal ( "AsyncPoolSink" , err)
271279 }
0 commit comments