【发布时间】:2022-10-17 18:22:31
【问题描述】:
我的项目有一个自定义的 HttpInterceptor 接口,可以实现它来拦截日志。
public interface HttpInterceptor {
default String getName() {
return getClass().getSimpleName();
}
default boolean isEnabled() {
return Boolean.TRUE;
}
default boolean validate(HttpExchange exchange) {
return Boolean.TRUE;
}
default HttpExchange postHandle(HttpExchange exchange) throws IOException {
return exchange;
}
default HttpExchange afterCompletion(HttpExchange exchange) throws IOException {
return exchange;
}
default HttpExchange preHandle(HttpExchange exchange) throws IOException {
return exchange;
}
}
现在,我有一个使用下面的代码实现上述拦截器的类。
public class Registrator implements HttpInterceptor {
@Override
public HttpExchange preHandle(HttpExchange exchange) throws IOException {
log.info("Getting intercepted for all Http calls");
return exchange;
}
@Override
public HttpExchange afterCompletion(HttpExchange exchange) throws IOException {
log.debug("Removing VIN from MDC");
}
}
我正在努力让这个拦截器在我的应用程序中打印任何 HttpCalls 的日志。
应该在我的 application.yml 文件中添加什么让 springboot 知道使用此拦截器进行日志记录? 如何在 application.yml 中设置日志级别拦截器?
记录: 等级: ??
【问题讨论】:
标签: java spring-boot logging https