[JAVA-14013] Added example for LoggingSystem

This commit is contained in:
panos-kakos
2023-06-29 18:36:48 +03:00
parent daef3dd7e9
commit 6ea7b339d3

View File

@@ -2,6 +2,8 @@ package com.baeldung.spring.boot.management.logging;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.logging.LogLevel;
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.RestController;
@@ -21,4 +23,12 @@ public class LoggingController {
return "See the log for details";
}
@GetMapping("/change-to-error")
public String changeLogLevelToError() {
LoggingSystem system = LoggingSystem.get(LoggingController.class.getClassLoader());
system.setLogLevel(LoggingController.class.getName(), LogLevel.ERROR);
return "changed log level to error";
}
}