nee*_*l21 7 logging spring-boot spring-boot-actuator
我想在 application.properties 文件中将 /health 执行器端点的记录器设置为 OFF。应用程序基于 Spring Boot 1.5。/health 将是 F5 的新监控 URL。我不想淹没日志。我有这个。
logging.level.org.springframework.web=DEBUG
org.springframework.boot.actuate.health.Logger=OFF
logging.level.org.springframework.boot.actuate.health=OFF
Run Code Online (Sandbox Code Playgroud)
我仍然在控制台和日志文件中收到 DEBUG 日志记录。唯一有效的是将第一个设置为 INFO 或更高。但是,这是不可取的。所以,现在我明白了
2020-05-06 17:14:01.545 DEBUG 58588 --- [nio-9095-exec-5] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/health]
2020-05-06 17:14:01.552 DEBUG 58588 --- [nio-9095-exec-5] o.s.web.servlet.DispatcherServlet : Last-Modified value for [/health] is: -1
2020-05-06 17:14:01.848 DEBUG 58588 --- [nio-9095-exec-5] m.m.a.RequestResponseBodyMethodProcessor : Written [UP {}] as "application/vnd.spring-boot.actuator.v1+json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@144409aa]
2020-05-06 17:14:01.849 DEBUG 58588 --- [nio-9095-exec-5] o.s.web.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2020-05-06 17:14:01.849 DEBUG 58588 --- [nio-9095-exec-5] o.s.web.servlet.DispatcherServlet : Successfully completed request
Run Code Online (Sandbox Code Playgroud)
我需要设置不同的记录器属性吗?对于不同的类/包?
我使用 logback,所以我为此添加了一个日志过滤器。您需要更改正则表达式以匹配您自己的日志记录格式。
package eu.stackoverflow.logging;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.FilterReply;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
public class IgnoringHealthAndPrometheusLoggingFilter extends Filter<ILoggingEvent> {
private static final Pattern HEALTH_OR_PROMETHEUS =
Pattern.compile("GET \"/(health|prometheus)\", parameters=\\{}");
private static final Pattern COMPLETED =
Pattern.compile("Completed 200 OK");
private Set<String> activeThreads = new HashSet<>();
@Override
public FilterReply decide(ILoggingEvent loggingEvent) {
if (isHealthOrPrometheus(loggingEvent.getMessage())) {
activeThreads.add(loggingEvent.getThreadName());
return FilterReply.DENY;
} else if (isCompleted200Ok(loggingEvent.getMessage()) && activeThreads.remove(loggingEvent.getThreadName())) {
return FilterReply.DENY;
} else {
return FilterReply.ACCEPT;
}
}
private boolean isHealthOrPrometheus(String message) {
return HEALTH_OR_PROMETHEUS.matcher(message).matches();
}
private boolean isCompleted200Ok(String message) {
return COMPLETED.matcher(message).matches();
}
}
Run Code Online (Sandbox Code Playgroud)
<appender class="ch.qos.logback.core.ConsoleAppender" name="CONSOLE">
<filter class="eu.stackoverflow.logging.IgnoringHealthAndPrometheusLoggingFilter" />
</appender>
Run Code Online (Sandbox Code Playgroud)
有关 logback 过滤器的更多信息:https ://logback.qos.ch/manual/filters.html
| 归档时间: |
|
| 查看次数: |
6873 次 |
| 最近记录: |