The article directories
-
-
- background
- implementation
-
- Online weblog
- Dynamically changing the log level
-
background
Viewing logs and changing log levels are common operations during project development.
The general operation mode is as follows:
Inconvenient and cumbersome to operate
Look what I achieved:
- Online weblog, can enter any location of the file, support to determine the path and relative path
- Dynamic log levels are set without service resetting
implementation
Online weblog
The core code
@RequestMapping(value = "/file", produces = "text/plain; charset=UTF-8")
public Resource logFile(@RequestParam(required = false) String filePath) {
if (StrUtil.isNotBlank(filePath)) {
filePathConfig = filePath;
}
Resource logFileResource = new FileSystemResource(new File(filePathConfig));
if (logFileResource == null| |! logFileResource.isReadable()) {return null;
}
return logFileResource;
}
Copy the code
Dynamically changing the log level
@RequestMapping(value = "/level") // Dynamically set the log level
public String configureLogLevel(String name, LogLevel configuredLevel) {
if (StrUtil.isBlank(name)) {
return "Please enter log name";
}
log.debug("name:{},level:{}", name, configuredLevel);
log.info("name:{},level:{}", name, configuredLevel);
log.warn("name:{},level:{}", name, configuredLevel);
log.error("name:{},level:{}", name, configuredLevel);
LoggerGroup group = this.loggerGroups.get(name);
if(group ! =null && group.hasMembers()) {
group.configureLogLevel(configuredLevel, this.loggingSystem::setLogLevel);
return "ok";
}
this.loggingSystem.setLogLevel(name, configuredLevel);
return "ok";
}
Copy the code
This section describes the functions of the log-related interfaces in the Spring-boot-starter -actuator.
LogFileWebEndpoint
To implement log browsing on the server sideLoggersEndpoint
To achieve log level query and dynamic setting
Another recommended another more powerful Xshell installation, Xftp, you can remote operation server, look at the black technology Spring Boot to achieve online Web SSH
Keep warm together and make progress together
🍎QQ group [837324215] 🍎 pay attention to my public number [Java Factory interview officer], learn together 🍎🍎🍎