java在异常处理期间何时使用记录器?
我是Java的新手,不知道什么时候使用logger。例如,在下面的示例中使用logger是否合乎逻辑。如何说“好的,我应该在这里使用记录器”。明确地说,我不是在问我应该使用哪个记录器,而是我应该使用记录器吗
public boolean isValid(Object bean, ConstraintValidatorContext ctx) {
try {
if (Assert.isNull(bean)) {
throw new NullPointerException(EXC_MSG_BEAN_NULL);
}
String dependentFieldActualValue;
dependentFieldActualValue = BeanUtils.getProperty(bean, dependentField);
boolean isActualEqual = stringEquals(dependentFieldValue, dependentFieldActualValue);
if (isActualEqual == ifInEqualThenValidate) {
return true; // The condition is not met => Do not validate at all.
}
return isTargetValid(bean, ctx); // Perform the actual validation on the target field
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
# 1 楼答案
伐木工人是很好的使用习惯。它们用于在不使用调试器的情况下或在生产环境中找出哪里出了问题以及哪里出了问题。 例如,当您对函数中作为参数的值有疑问,并且希望检查是否传递了正确的值时,可以在调试级别记录该值,以便确保传递了正确的值,如果没有,则可以更正