You're not doing anything wrong. With asynchronous logging, immediateFlush=false in Log4j 2 effectively means "only flush when necessary or at end of batch".
Buffered logging has great performance benefits but has the drawback that often you cannot see the most recent log output because it hasn't been flushed to disk yet.
Asynchronous logging in Log4j 2 uses "smart batching": the buffer is flushed not only when it is full, but also when the queue of log events became empty and the background thread doesn't have any other work to do.
This has the benefit that your log events are immediately visible on disk, but is much more efficient than setting immediateFlush=true.
Asked in February 2016Viewed 2,223 timesVoted 7Answered 1 times