[JAVA-14013] Added example for LoggingSystem

This commit is contained in:
panos-kakos 2023-06-29 18:36:48 +03:00
parent cd6661e117
commit b71e52fc8b
1 changed files with 10 additions and 0 deletions

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";
}
}