LOG4J2-2629: PurgePolicy implementations can invoke
RoutingAppender.deleteAppender(String)
after we have looked up
an instance of a target appender but before events are appended, which could result in events not being
recorded to any appender.
This extension of
AppenderControl
allows to to mark usage of an appender, allowing deferral of
LifeCycle.stop()
until events have successfully been recorded.
Alternative approaches considered:
- More aggressive synchronization: Appenders may do expensive I/O that shouldn't block routing.
- Move the 'updatePurgePolicy' invocation before appenders are called: Unfortunately this approach doesn't work
if we consider an ImmediatePurgePolicy (or IdlePurgePolicy with a very small timeout) because it may attempt
to remove an appender that doesn't exist yet. It's counterintuitive to get an event that a route has been
used at a point when we expect the route doesn't exist in
RoutingAppender.getAppenders()
.