Hi Gena,
The intent of the shutdown hook functionality is not to be a general application shutdown hook, but to provide reasonably ways of having logback wait for a some condition before shutting down (not just calling LoggerContext.stop immediately). Logback can provide one or more general mechanisms for performing this action, however if the user's needs differ they could implement their own.
The benefit of utilizing a logback based shutdown hook for cleaning up logback resources is that logback can ensure that shutdown hook is properly removed when the context is reset (which reduces the complexity of using the Runtime hook methods directly). Additionally, the user can utilize existing, tested implementations if one of the Logback provided shutdown hook mechanisms is appropriate for the user's application or scenario.
Just because a shutdown hook implementation is simple (such as a one-liner) does not make the logback managed mechanism invalid or irrelevant. The user still has the choice to implement a hook however they choose - via a predefined, managed hook or a completely custom hook.
I'm not sure how this design is premature optimization. It is a very simple design for flexibility - there is no impact to speed, debuggability, or maintenance. Though some may qualify it as "you aren't going to need it", YAGNI more accurately refers to features which significantly take away from the development of core functionality, testing, documentation, etc or add significant complexity, limit future flexibility, etc. The ShutdownHookAction and associated classes are compact, well-defined, do not detract from the maintainability of logback as a whole, do not add significant complexity, nor limit future flexibility.
To be completely honest, Ceki first suggested using a Joran action about a week ago. Since then I have only spent about 4 hours researching, developing, and testing the ShutdownActionHook solution - which is now 100% complete from a functionality standpoint and 95% complete overall (just pending documentation and some unit testing). The other changes to AsyncAppender had been built into a proof of concept and re-implemented with suggestions from the pull request over a week ago. I have probably spent more time debating the merits of your proposal vs mine than actually researching, developing, testing, and documenting! :)
Not that I regret the debate by any means - it has been a healthy design discussion and has helped to clarify other use-cases and mechanisms that I may not have thought of otherwise. That being said, with buy-in from maintainers of Logback on this design (at least to this point), I don't see much point in debating further. It still seems to me that the best solution is the blending of our two proposals - using my structure to provide flexibility and your solution to transition the logback mode. Since my solution is nearly complete and yours may be a ways off, this seems like a natural fit both technically and logistically. That being said, if anyone from Logback team wants to weigh in on how they feel would be best to proceed in light of the proposals and discussion, I am open to proceeding with the result of the group decision.
At the very least, regardless of what proposal or blending of proposals is approved, I believe that the changes already made to the AsyncAppender in the open pull request are still valid since that is what ensures that LoggerContext.stop does not return until AsyncAppender has flushed its queue or reached its configured timeout. From my perspective, it is just the discussion around the shutdown hook implementation components that is in contention, agreed?
Thanks!
Regards,
Mike Reinhold