For some troubleshooting reasons I'd like to log all past messages (for example last 20) on level from TRACE if there occurred an exception, but if code works well I'd like to log from INFO level to keep clear my log files from unnecessary log messages.
For example:
public void m( String arg ){
log.trace( "arg value: " + arg );
log.info( "Hi Bob!" );
try{
//code
}catch( Exception e ){
log.error( "error msg", e );
}
}
I'd like to get in log something like:
*INFO* Hi Bob!
But if the error is occurred I'd like to get in log something like:
*TRACE* arg value: test
*INFO* Hi Bob!
*ERROR* error msg //and stacktrace
In other words I'd like to have a log message buffer that will cleared from low level messages if code runs well and pushed in log files in case of error. Can java logging framework do this from the box?