I am using slf4j 1.7.x for logging in our Java project. The Logger interface has multiple methods to log at ERROR level such as these two:
void error(String msg, Throwable t)
void error(String format, Object... arguments)
My question is, if I would like to log an exception in my catch block which of these two is considered better and what information is logged in which one, if I have it as follows?
try {
// Code to call sdk for ABC Service
} catch (AbcServiceException | CredentialException | IOException e) {
logger.error("Error during getting information from Abc", e);
//OR
logger.error("Error during getting information from Abc {} {} ", e.getMessage(), e.getCause());
return null; // Or return some default value
}