logback动态修改日志级别

public class LogController {

    @RequestMapping("/change")
    public String changeLog(String packageName, String level) {
        LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
        loggerContext.getLogger(packageName).setLevel(Level.valueOf(level));
        return "change log success";
    }

    @RequestMapping("/query")
    public String getAllLogs() {
        LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
        List loggerList = loggerContext.getLoggerList();
        String res = loggerList.stream().map(Logger::getName).collect(Collectors.joining(","));
        System.out.println(res);
        return res;
    }
}

springBoot 版本1.5 + 以后 已经支持动态修改

你可能感兴趣的:(微服务)