diff --git a/tutorials/katacoda/case-ognl-update-logger-level-cn/arthas-boot.md b/tutorials/katacoda/case-ognl-update-logger-level-cn/arthas-boot.md new file mode 100644 index 000000000..5c6cb8a17 --- /dev/null +++ b/tutorials/katacoda/case-ognl-update-logger-level-cn/arthas-boot.md @@ -0,0 +1,16 @@ + + + + +在新的`Terminal 2`里,下载`arthas-boot.jar`,再用`java -jar`命令启动: + +`wget https://arthas.aliyun.com/doc/arthas-boot.jar +java -jar arthas-boot.jar`{{execute T2}} + +`arthas-boot`是`Arthas`的启动程序,它启动后,会列出所有的Java进程,用户可以选择需要诊断的目标进程。 + +选择第一个进程,输入 `1`{{execute T2}} ,再`Enter/回车`: + +Attach成功之后,会打印Arthas LOGO。输入 `help`{{execute T2}} 可以获取到更多的帮助信息。 + +![Arthas Boot](/arthas/scenarios/common-resources/assets/arthas-boot.png) diff --git a/tutorials/katacoda/case-ognl-update-logger-level-cn/case-ognl-update-logger-level.md b/tutorials/katacoda/case-ognl-update-logger-level-cn/case-ognl-update-logger-level.md new file mode 100644 index 000000000..d367a3bd4 --- /dev/null +++ b/tutorials/katacoda/case-ognl-update-logger-level-cn/case-ognl-update-logger-level.md @@ -0,0 +1,87 @@ + + +在这个案例里,动态修改应用的Logger Level。 + + +### 查找UserController的ClassLoader + +`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 +``` + +注意hashcode是变化的,需要先查看当前的ClassLoader信息,提取对应ClassLoader的hashcode。 + +如果你使用`-c`,你需要手动输入hashcode:`-c ` + +```bash +$ ognl -c 1be6f5c3 @com.example.demo.arthas.user.UserController@logger +``` + +对于只有唯一实例的ClassLoader可以通过`--classLoaderClass`指定class name,使用起来更加方便: + +```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]], +] +``` + +`--classLoaderClass` 的值是ClassLoader的类名,只有匹配到唯一的ClassLoader实例时才能工作,目的是方便输入通用命令,而`-c `是动态变化的。 + +### 用ognl获取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]], +] +``` + +可以知道`UserController@logger`实际使用的是logback。可以看到`level=null`,则说明实际最终的level是从`root` logger里来的。 + +### 单独设置UserController的logger level + +`ognl --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader '@com.example.demo.arthas.user.UserController@logger.setLevel(@ch.qos.logback.classic.Level@DEBUG)'`{{execute T2}} + +再次获取`UserController@logger`,可以发现已经是`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]], +] +``` + +### 修改logback的全局logger level + +通过获取`root` logger,可以修改全局的logger level: + +`ognl --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader '@org.slf4j.LoggerFactory@getLogger("root").setLevel(@ch.qos.logback.classic.Level@DEBUG)'`{{execute T2}} + diff --git a/tutorials/katacoda/case-ognl-update-logger-level-cn/finish.md b/tutorials/katacoda/case-ognl-update-logger-level-cn/finish.md new file mode 100644 index 000000000..471da2303 --- /dev/null +++ b/tutorials/katacoda/case-ognl-update-logger-level-cn/finish.md @@ -0,0 +1,10 @@ + +通过本教程基本掌握了Arthas动态更新应用Logger Level。更多高级特性,可以在下面的进阶指南里继续了解。 + +* [Arthas进阶](https://arthas.aliyun.com/doc/arthas-tutorials?language=cn&id=arthas-advanced) +* [Arthas Github](https://github.com/alibaba/arthas) +* [Arthas 文档](https://arthas.aliyun.com/doc/) + +欢迎关注公众号,获取Arthas项目的信息,源码分析,案例实践。 + +![Arthas公众号](/arthas/scenarios/common-resources/assets/qrcode_gongzhonghao.jpg) diff --git a/tutorials/katacoda/case-ognl-update-logger-level-cn/index.json b/tutorials/katacoda/case-ognl-update-logger-level-cn/index.json new file mode 100644 index 000000000..1c0078bd7 --- /dev/null +++ b/tutorials/katacoda/case-ognl-update-logger-level-cn/index.json @@ -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" + } +} \ No newline at end of file diff --git a/tutorials/katacoda/case-ognl-update-logger-level-cn/intro.md b/tutorials/katacoda/case-ognl-update-logger-level-cn/intro.md new file mode 100644 index 000000000..305296638 --- /dev/null +++ b/tutorials/katacoda/case-ognl-update-logger-level-cn/intro.md @@ -0,0 +1,11 @@ + + + +![Arthas](https://arthas.aliyun.com/doc/_images/arthas.png) + +`Arthas` 是Alibaba开源的Java诊断工具,深受开发者喜爱。在线排查问题,无需重启;动态跟踪Java代码;实时监控JVM状态。 + +`Arthas` 支持JDK 6+,支持Linux/Mac/Windows,采用命令行交互模式,同时提供丰富的 `Tab` 自动补全功能,进一步方便进行问题的定位和诊断。 + +* Github: https://github.com/alibaba/arthas +* 文档: https://arthas.aliyun.com/doc/ \ No newline at end of file diff --git a/tutorials/katacoda/case-ognl-update-logger-level-cn/start-demo.md b/tutorials/katacoda/case-ognl-update-logger-level-cn/start-demo.md new file mode 100644 index 000000000..59be66ea6 --- /dev/null +++ b/tutorials/katacoda/case-ognl-update-logger-level-cn/start-demo.md @@ -0,0 +1,14 @@ + + + + +下载`demo-arthas-spring-boot.jar`,再用`java -jar`命令启动: + +`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`是一个很简单的spring boot应用,源代码:[查看](https://github.com/hengyunabc/spring-boot-inside/tree/master/demo-arthas-spring-boot) + +启动之后,可以访问80端口: https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com + +![Demo Web](/arthas/scenarios/common-resources/assets/demo-web.png) \ No newline at end of file diff --git a/tutorials/katacoda/case-ognl-update-logger-level-en/arthas-boot.md b/tutorials/katacoda/case-ognl-update-logger-level-en/arthas-boot.md new file mode 100644 index 000000000..5f6d3f246 --- /dev/null +++ b/tutorials/katacoda/case-ognl-update-logger-level-en/arthas-boot.md @@ -0,0 +1,16 @@ + + + + +In the new `Terminal 2`, download `arthas-boot.jar` and start with the `java -jar` command: + +`wget https://arthas.aliyun.com/doc/arthas-boot.jar +java -jar arthas-boot.jar`{{execute T2}} + +`arthas-boot` is the launcher for `Arthas`. It lists all the Java processes, and the user can select the target process to be diagnosed. + +Select the first process, type `1`{{execute T2}} ,then type `Enter`: + +After the Attach is successful, Arthas LOGO is printed. Enter `help`{{execute T2}} for more help. + +![Arthas Boot](/arthas/scenarios/common-resources/assets/arthas-boot.png) diff --git a/tutorials/katacoda/case-ognl-update-logger-level-en/case-ognl-update-logger-level.md b/tutorials/katacoda/case-ognl-update-logger-level-en/case-ognl-update-logger-level.md new file mode 100644 index 000000000..4d2c84f0b --- /dev/null +++ b/tutorials/katacoda/case-ognl-update-logger-level-en/case-ognl-update-logger-level.md @@ -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 `. + +```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 ` 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}} + diff --git a/tutorials/katacoda/case-ognl-update-logger-level-en/finish.md b/tutorials/katacoda/case-ognl-update-logger-level-en/finish.md new file mode 100644 index 000000000..3e04b8ff7 --- /dev/null +++ b/tutorials/katacoda/case-ognl-update-logger-level-en/finish.md @@ -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) diff --git a/tutorials/katacoda/case-ognl-update-logger-level-en/index.json b/tutorials/katacoda/case-ognl-update-logger-level-en/index.json new file mode 100644 index 000000000..f6389e34a --- /dev/null +++ b/tutorials/katacoda/case-ognl-update-logger-level-en/index.json @@ -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" + } +} \ No newline at end of file diff --git a/tutorials/katacoda/case-ognl-update-logger-level-en/intro.md b/tutorials/katacoda/case-ognl-update-logger-level-en/intro.md new file mode 100644 index 000000000..c27afd332 --- /dev/null +++ b/tutorials/katacoda/case-ognl-update-logger-level-en/intro.md @@ -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 \ No newline at end of file diff --git a/tutorials/katacoda/case-ognl-update-logger-level-en/start-demo.md b/tutorials/katacoda/case-ognl-update-logger-level-en/start-demo.md new file mode 100644 index 000000000..4915b847a --- /dev/null +++ b/tutorials/katacoda/case-ognl-update-logger-level-en/start-demo.md @@ -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) \ No newline at end of file