1
votes

How to log all levels' events (i.e info, debug, trace, warn, error and fatal) only when error, fatal or warn level log events are encountered otherwise log only info levels. This ensures that debug and trace logs (which are usually very large) are logged only when necessary (i.e. when there are detected warnings or errors) and hence saves space and accelerates performance.

1
How many log events before the error-level event should be buffered so they can be flushed when the error-level event occurs? --- How many, or for how long, should log events after the error-level event be logged? - Andreas
It basically means that you want to keep an X log events in memory in a queue until an error arrives, then flush the queue. Or, if no error arrives keep chopping queue's tail to keep only X events and not more. I don't think there's a solution out of the box, you'll have to roll a custom handler or something, depending on what actual logging you're using. - M. Prokhorov
@Andreas There is no limit like that. All events before have to be queued somehow. If at termination we haven't encountered error level yet, then the queue is cleared. If we encounter an error, all previous logs and all logs after encountering such an event will be logged. - Akshay G Rao
@M.Prokhorov What is the best way to do it. Does any logging framework provide such a facility by changing configurations. - Akshay G Rao
@AkshayGRao Best way: Create a new log file on startup. On program exit, delete the file if no errors. Prevents the need for wasting a lot of memory caching the log entries. Create a custom Appender to effectuate that. - Andreas

1 Answers

0
votes

I would suggest you vote for LOG4J2-1137.