spring boot 動態修改日誌級別
阿新 • • 發佈:2020-09-10
spring boot 版本 2.3.3
import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.logging.LogLevel; import org.springframework.boot.logging.LoggerConfiguration; import org.springframework.boot.logging.LoggingSystem; import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController @RequestMapping("/test") @Slf4j public class TestController { @Autowiredprivate LoggingSystem loggingSystem; @GetMapping("") public Object getActiveProfiles() { log.info("test"); List<LoggerConfiguration> loggerConfigurations = loggingSystem.getLoggerConfigurations(); return loggerConfigurations; } @GetMapping("update")public Object update( @RequestParam String name, @RequestParam LogLevel level ) { loggingSystem.setLogLevel(name,level); return "ok"; } }