Flush all pending messages on shutdown
Closed this issue · 1 comments
I have noticed that on shutdown of the JVM - it doesn't look like all the messages are flushed out to Sumo.
I have a short-running batch process (running in AWS Batch) which terminates (with System.exit) at the end of it's processing. I am noticing that not all the messages logged are being sent to Sumo - and i think it is because there are still messages in the buffer which are not sent on shutdown.
I have looked at the code and can't see a way to explicitly flush messages (which would work for me). It looks like the best I can do is to set the messagesPerRequest to a low number (10ish) and the maxFlushInterval to a smaller number in order to make sure messages are flushed more often. This doesn't guarantee that all the messages are sent however.
Maybe the stop() method on the SumoLogicAppender could flush all pending messages prior to calling sender.close() and flusher.stop()?
Or - add a shutdown hook to send messages before the JVM shuts down?
log4j exposes a stop
hook, however it appears the JVM will still shut down without waiting any time for the network I/O to complete. As far as I can tell, the best you can do is adjust the messagesPerRequest
and maxFlushInterval
to minimize the amount of unsent data at the time of JVM shutdown. To capture all of the data, you can install a Collector agent to read from the log file on disk.