Monday, 15 April 2013

java - Logging on all levels for some past log messages in case of exception and log on info level in normal case -



java - Logging on all levels for some past log messages in case of exception and log on info level in normal case -

for troubleshooting reasons i'd log past messages (for illustration lastly 20) on level trace if there occurred exception, if code works i'd log info level maintain clear log files 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 in log like:

*info* hi bob!

but if error occurred i'd in log like:

*trace* arg value: test *info* hi bob! *error* error msg //and stacktrace

in other words i'd have log message buffer cleared low level messages if code runs , pushed in log files in case of error. can java logging framework box?

i uncertainty can such thing log4j, unfortunately. think can 2 other things:

write info need in error message (not practical)

log.error( "error arg value " + arg, e );

configure log4j prints level info in console or log file , print level trace in file, called "detailed.log", in case of error. details how see question.

java logging log4j

No comments:

Post a Comment