Spring Cloud Spring Boot mybatis Distributed Microservice Cloud Architecture (45) Dynamically modify the log level (2)

Test verification

After completing the above build, we start the sample application and access /testthe endpoint, we can see the following output in the console:

2017-01-31 22:34:57.123  INFO 16372 --- [nio-8000-exec-1] ication$$EnhancerBySpringCGLIB$$d2a0b1e2 : Logger Level :INFO
2017-01-31 22:34:57.124 ERROR 16372 --- [nio-8000-exec-1] ication$$EnhancerBySpringCGLIB$$d2a0b1e2 : Logger Level :ERROR

Since the default log level is INFO, there is no output DEBUGlevel content. Below we can try /loggerto adjust the log level through the endpoint DEBUG, for example, send a POST request to the /loggers/com.didispaceendpoint, where the body content of the request body is:

{
    "configuredLevel": "DEBUG"
}

Revisiting /testthe endpoint, we will see the following output in the console, /testthe log content defined in the endpoint DEBUGis printed out:

2017-01-31 22:37:35.252 DEBUG 16372 --- [nio-8000-exec-5] ication$$EnhancerBySpringCGLIB$$d2a0b1e2 : Logger Level :DEBUG
2017-01-31 22:37:35.252  INFO 16372 --- [nio-8000-exec-5] ication$$EnhancerBySpringCGLIB$$d2a0b1e2 : Logger Level :INFO
2017-01-31 22:37:35.252 ERROR 16372 --- [nio-8000-exec-5] ication$$EnhancerBySpringCGLIB$$d2a0b1e2 : Logger Level :ERROR

As you can see, so far, we have not restarted the Spring Boot application, but simply /loggerscontrolled the log level update by calling the endpoint. In addition to POST requests, we can also view the current log level settings through GET requests, such as: sending a GET request to an /loggers/com.didispaceendpoint, we will get com.didispacethe log level settings for the package:

{
  "configuredLevel": "DEBUG",
  "effectiveLevel": "DEBUG"
}

We can also get all the log level settings directly through GET request access without limiting the conditions. /loggersThe specific returns are not listed here, and readers can try it by themselves. source code

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325856428&siteId=291194637