我设置了一个spring-boot应用程序,包括使用log4j进行日志记录。在应用程序中,有几个层,例如controller, service, models, repositories, exception
等。目前,我已在exception
层中包含 ERROR 级别日志。
@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);
}
}
答案 0 :(得分:1)
第一个问题的答案: 记录是一种所谓的“交叉问题”,这意味着它与问题域无关,因此它在代码中的每个层都出现。
您的第二个问题在这里得到解答: How to determine what log level to use?