I have a spring-boot application set-upped including logging using log4j. In the application, there are few layers such as controller, service, models, repositories, exception
etc. At the moment, i have included ERROR level logs in the exception
layer.
@Component
public class ExceptionFactory {
private static final Logger LOG = LoggerFactory.getLogger(ExceptionFactory.class);
public static ApplicationSpecificException create(final Throwable cause, final ExceptionType exceptionType, final Object... messageArguments) {
LOG.error(MessageFormat.format(exceptionType.getMessage(), messageArguments), cause);
return new ApplicationSpecificException (exceptionType, cause, messageArguments);
}
public static ApplicationSpecificException create(final ExceptionType exceptionType, final Object... messageArguments) {
LOG.error(MessageFormat.format(exceptionType.getMessage(), messageArguments));
return new ApplicationSpecificException(exceptionType, messageArguments);
}
}
- Is it appropriate to use logging in any of the above mentioned layers?
- Log4j has log level such as FATAL, ERROR, WARN, INFO, DEBUG and TRACE . How to identify the situations to use these level when logging in Spring applications ?