Merge pull request #14328 from panos-kakos/JAVA-14013

[JAVA-14013] Added example for LoggingSystem
This commit is contained in:
Kasra Madadipouya 2023-07-09 21:21:52 +02:00 committed by GitHub
commit 3f76369a97
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";
}
}