摘要
Spring Boot
在日志的配置上为我们做了众多的自动化工作,详细参见《寻根究底 Logging - Spring Boot 日志概述》。
从版本 1.5.1
之后就提供了基于 spring-boot-starter-actuator
的端点 /loggers
。通过该端点可以实现查看系统的 package-path
的日志级别,以及针对特定的 package-path
配置运行中的应用的日志级别的功能。
Actuator 依赖
pom 依赖
因为是基于 Web 的项目和利用 Actuator 提供的端点来进行配置,因此需要依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
安全配置
Actuator
提供的端点(Endpoints),默认是需要安全认证才能够被访问的。因为里面涉及到一些敏感的信息。需要安全认证就需要配置 Spring-Security
。为了方便首先配置不需要安全权限的。
management.security.enabled=false
GET 请求访问
我们可以发送GET
请求到 http://localhost:8080/loggers
来获取支持的日志等级,以及系统默认的日志等和各个包路径对应的日志级别。
{
levels: [
"OFF",
"ERROR",
"WARN",
"INFO",
"DEBUG",
"TRACE"
],
loggers: {
ROOT: {
configuredLevel: "INFO",
effectiveLevel: "INFO"
},
cn: {
configuredLevel: null,
effectiveLevel: "INFO"
},
cn.cincou