Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

When does SemanticLogger call SemanticLogger.close? #214

Answered by reidmorrison
aniruddhb asked this question in Q&A
Discussion options

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!

You must be logged in to vote

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

Comment options

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.

You must be logged in to vote
0 replies
Answer selected by reidmorrison
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /