-
-
Notifications
You must be signed in to change notification settings - Fork 136
When does SemanticLogger call SemanticLogger.close?
#214
-
Hello!
Firstly, fantastic library. Do you take sponsorship / donations for the project (e.g. via OpenCollective)? Really appreciate the quality & effort put into this piece of software.
I'm trying to understand when SemanticLogger.close is called.
I noticed in release 4.2.0 (changelog) that the library now calls SemanticLogger.flush inside at_exit instead of SemanticLogger.close.
As a proof-of-concept, I created a sample Rails app with an appender, and overrode the .flush & .close methods inside the appender with some print statements (e.g. puts "calling .flush" or puts "calling .close"). When my Rails application terminates, it seems like .flush is called once, and .close is not called at all.
I was wondering
- am I missing something w.r.t the behavior of
.close - are there any other lifecycle methods that can be hooked into to fully close an appender & release its resources? (In my appender, I am instantiating an API client that talks to a logging destination, and I'd like to close the API client in the appender when my Rails application terminates)
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions
If I recall correctly the reason it calls flush and not close is because of test frameworks. They register tests as part of the at_exit logic, so the close was being called before the tests had a chance to run, preventing any logging from being processed. Give it a try locally. Will be happy to change it back to .close instead of .flush if we can make it also work during tests.
Replies: 1 comment
-
If I recall correctly the reason it calls flush and not close is because of test frameworks. They register tests as part of the at_exit logic, so the close was being called before the tests had a chance to run, preventing any logging from being processed. Give it a try locally. Will be happy to change it back to .close instead of .flush if we can make it also work during tests.
Beta Was this translation helpful? Give feedback.