mirror of https://github.com/alibaba/arthas.git
parent
306866ae12
commit
20a5fdacab
@ -0,0 +1,45 @@
|
||||
{
|
||||
"title": "Arthas 动态更新应用Logger Level 案例",
|
||||
"description": "Arthas 动态更新应用Logger Level 案例",
|
||||
"difficulty": "高级使用者",
|
||||
"time": "10分钟",
|
||||
"details": {
|
||||
"steps": [
|
||||
{
|
||||
"title": "Start demo",
|
||||
"text": "start-demo.md"
|
||||
},
|
||||
{
|
||||
"title": "Start arthas-boot",
|
||||
"text": "arthas-boot.md"
|
||||
},
|
||||
{
|
||||
"title": "动态更新应用Logger Level",
|
||||
"text": "case-ognl-update-logger-level.md"
|
||||
}
|
||||
],
|
||||
"intro": {
|
||||
"text": "intro.md"
|
||||
},
|
||||
"finish": {
|
||||
"text": "finish.md"
|
||||
},
|
||||
"assets": {
|
||||
"host01": []
|
||||
}
|
||||
},
|
||||
"environment": {
|
||||
"uilayout": "terminal",
|
||||
"showdashboard": true,
|
||||
"dashboards": [
|
||||
{
|
||||
"name": "Web Port 80",
|
||||
"port": 80
|
||||
}
|
||||
]
|
||||
},
|
||||
"backend": {
|
||||
"imageid": "java",
|
||||
"environmentsprotocol": "http"
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
|
||||
In this case, show how to dynamically modify the Logger Level.
|
||||
|
||||
### Find the ClassLoader of the UserController
|
||||
|
||||
`sc -d com.example.demo.arthas.user.UserController | grep classLoaderHash`{{execute T2}}
|
||||
|
||||
```bash
|
||||
$ sc -d com.example.demo.arthas.user.UserController | grep classLoaderHash
|
||||
classLoaderHash 1be6f5c3
|
||||
```
|
||||
|
||||
Please write down your classLoaderHash here since it's dynamic. In the case here, it's `1be6f5c3`.
|
||||
|
||||
if you use`-c`, you have to manually type hashcode by `-c <hashcode>`.
|
||||
|
||||
```bash
|
||||
$ ognl -c 1be6f5c3 @com.example.demo.arthas.user.UserController@logger
|
||||
```
|
||||
|
||||
For classloader with only one instance, it can be specified by `--classLoaderClass` using class name, which is more convenient to use.
|
||||
|
||||
```bash
|
||||
$ ognl --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader @org.springframework.boot.SpringApplication@logger
|
||||
@Slf4jLocationAwareLog[
|
||||
FQCN=@String[org.apache.commons.logging.LogAdapter$Slf4jLocationAwareLog],
|
||||
name=@String[org.springframework.boot.SpringApplication],
|
||||
logger=@Logger[Logger[org.springframework.boot.SpringApplication]],
|
||||
]
|
||||
```
|
||||
|
||||
The value of `--classloaderclass` is the class name of classloader. It can only work when it matches a unique classloader instance. The purpose is to facilitate the input of general commands. However, `-c <hashcode>` is dynamic.
|
||||
|
||||
### Use ognl command to get the logger
|
||||
|
||||
`ognl --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader '@com.example.demo.arthas.user.UserController@logger'`{{execute T2}}
|
||||
|
||||
```bash
|
||||
$ ognl --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader '@com.example.demo.arthas.user.UserController@logger'
|
||||
@Logger[
|
||||
serialVersionUID=@Long[5454405123156820674],
|
||||
FQCN=@String[ch.qos.logback.classic.Logger],
|
||||
name=@String[com.example.demo.arthas.user.UserController],
|
||||
level=null,
|
||||
effectiveLevelInt=@Integer[20000],
|
||||
parent=@Logger[Logger[com.example.demo.arthas.user]],
|
||||
childrenList=null,
|
||||
aai=null,
|
||||
additive=@Boolean[true],
|
||||
loggerContext=@LoggerContext[ch.qos.logback.classic.LoggerContext[default]],
|
||||
]
|
||||
```
|
||||
|
||||
The user can know that `UserController@logger` actually uses logback. Because `level=null`, the actual final level is from the `root` logger.
|
||||
|
||||
### Change the logger level of UserController
|
||||
|
||||
`ognl --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader '@com.example.demo.arthas.user.UserController@logger.setLevel(@ch.qos.logback.classic.Level@DEBUG)'`{{execute T2}}
|
||||
|
||||
Get `UserController@logger` again, the user can see that it is already `DEBUG`:
|
||||
|
||||
`ognl --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader '@com.example.demo.arthas.user.UserController@logger'`{{execute T2}}
|
||||
|
||||
```bash
|
||||
$ ognl --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader '@com.example.demo.arthas.user.UserController@logger'
|
||||
@Logger[
|
||||
serialVersionUID=@Long[5454405123156820674],
|
||||
FQCN=@String[ch.qos.logback.classic.Logger],
|
||||
name=@String[com.example.demo.arthas.user.UserController],
|
||||
level=@Level[DEBUG],
|
||||
effectiveLevelInt=@Integer[10000],
|
||||
parent=@Logger[Logger[com.example.demo.arthas.user]],
|
||||
childrenList=null,
|
||||
aai=null,
|
||||
additive=@Boolean[true],
|
||||
loggerContext=@LoggerContext[ch.qos.logback.classic.LoggerContext[default]],
|
||||
]
|
||||
```
|
||||
|
||||
### Change the global logger level of the logback
|
||||
|
||||
By getting the `root` logger, the user can modify the global logger level:
|
||||
|
||||
`ognl --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader '@org.slf4j.LoggerFactory@getLogger("root").setLevel(@ch.qos.logback.classic.Level@DEBUG)'`{{execute T2}}
|
||||
|
@ -0,0 +1,6 @@
|
||||
|
||||
Through this tutorial, you can know how to Change Logger Level. More advanced features can be found in the Advanced Guide below.
|
||||
|
||||
* [Arthas Advanced](https://arthas.aliyun.com/doc/arthas-tutorials?language=en&id=arthas-advanced)
|
||||
* [Arthas Github](https://github.com/alibaba/arthas)
|
||||
* [Arthas Documentation](https://arthas.aliyun.com/doc/en)
|
@ -0,0 +1,45 @@
|
||||
{
|
||||
"title": "Arthas Change Logger Level",
|
||||
"description": "Arthas Change Logger Level",
|
||||
"difficulty": "expert",
|
||||
"time": "10 minutes",
|
||||
"details": {
|
||||
"steps": [
|
||||
{
|
||||
"title": "Start demo",
|
||||
"text": "start-demo.md"
|
||||
},
|
||||
{
|
||||
"title": "Start arthas-boot",
|
||||
"text": "arthas-boot.md"
|
||||
},
|
||||
{
|
||||
"title": "Change Logger Level",
|
||||
"text": "case-ognl-update-logger-level.md"
|
||||
}
|
||||
],
|
||||
"intro": {
|
||||
"text": "intro.md"
|
||||
},
|
||||
"finish": {
|
||||
"text": "finish.md"
|
||||
},
|
||||
"assets": {
|
||||
"host01": []
|
||||
}
|
||||
},
|
||||
"environment": {
|
||||
"uilayout": "terminal",
|
||||
"showdashboard": true,
|
||||
"dashboards": [
|
||||
{
|
||||
"name": "Web Port 80",
|
||||
"port": 80
|
||||
}
|
||||
]
|
||||
},
|
||||
"backend": {
|
||||
"imageid": "java",
|
||||
"environmentsprotocol": "http"
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
|
||||
![Arthas](https://arthas.aliyun.com/doc/_images/arthas.png)
|
||||
|
||||
`Arthas` is a Java diagnostic tool open-sourced by Alibaba middleware team. Arthas helps developers in trouble-shooting issues in production environment for Java based applications without modifying code or restarting servers.
|
||||
|
||||
`Arthas` supports JDK 6+, supports Linux/Mac/Windows.
|
||||
|
||||
* Github: https://github.com/alibaba/arthas
|
||||
* Documentation: https://arthas.aliyun.com/doc/en
|
@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
|
||||
|
||||
Download `demo-arthas-spring-boot.jar`, and start with `java -jar` command:
|
||||
|
||||
`wget https://github.com/hengyunabc/spring-boot-inside/raw/master/demo-arthas-spring-boot/demo-arthas-spring-boot.jar
|
||||
java -jar demo-arthas-spring-boot.jar`{{execute T1}}
|
||||
|
||||
`demo-arthas-spring-boot` is a simple Spring Boot demo, the source code here: [View](https://github.com/hengyunabc/spring-boot-inside/tree/master/demo-arthas-spring-boot)
|
||||
|
||||
After booting, access port 80: https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com
|
||||
|
||||
![Demo Web](/arthas/scenarios/common-resources/assets/demo-web.png)
|
Loading…
Reference in New Issue