I am using commons logging in a Java application, and I want to log the exception from the stack trace.
catch( IOException exception ) {
logger.error( "IOException Occured :", exception.fillInStackTrace() );
//Print the entire stack trace to log file.
throw new AsExceptionUtl( APPMessageHelper.getMessage( APPMessageConstants.ERROR_FailedLoadFile, documentPath ) );
}
Is this the right way ? And will it print the stacktrace in the log ?
If you want to log the exception, then just use
logger.error("IOException Occured :", exception);
Whether the stack trace will be displayed or not depends on what the underlying logging implementation is, and how it's configured. AFAIK, most or all implementations do display the stack trace of the exceptions by default.