Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to dynamically modify the Logger level of online troubleshooting skills

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to dynamically modify the Logger level of online troubleshooting skills". In the daily operation, I believe that many people have doubts about how to dynamically modify the Logger level of online troubleshooting skills. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for everyone to answer the doubts of "how to dynamically modify the Logger level of online troubleshooting skills." Next, please follow the editor to study!

"effect demonstration:"

"the focus of this article is:"

Brief introduction of Arthas tool

Local testing: real-time modification of LOGGER level

Online practice: printing MyBatis SQL statements in real time

Summary

Introduction to Arthas tools Arthas is an open source Java diagnostic tool provided by Ali. Its functions can be roughly referenced to the following figure:

The principle of it is to weave the agent logic into the original class through the bytecode generation tool (ASM bytecode enhancement) to achieve the corresponding monitoring and debugging functions.

Local testing: real-time modification of LOGGER level

Install arthas

Network installation

In the environment of connecting to the public network, you can use fast network installation, which will pull all the packets from Ali's source.

Curl-O https://arthas.aliyun.com/arthas-boot.jar java-jar arthas-boot.jar

Full installation

If the local public network environment is not accessible, for example, public network access is not allowed in some containers, then you can use the full installation package downloaded in advance, then decompress and run the jar in the package, using the command:

Java-jar arthas-boot.jar

Start arthas. I start arthas locally. The effect is as follows:

Global Logger information

Use the command:

Logger

You can see information about all the logger, including each appenders.

Use the following command to change the log level of the logger named ROOT to the debug level:

Logger-name ROOT-level debug

You can see that there is more output than the debug level.

Specify the logger information for the class name

In the case of multiple logger, you can find the logger with the specified name

Logger-n ROOT

Specify logger information for classloader

If you need to change the output level of the specified class, first navigate to the classLoader of the class, and then modify the logger of the clasLoader.

Sc-d cn.monitor4all.miaoshaweb.DynamicLoggerTest | grep classLoaderHash

Use the sc command to view the class information you need to change:

You can then find its corresponding logger through classLoader:

Logger-c 18b4aac2

Then you can adjust the corresponding logger log level:

Logger-c 18b4aac2-- name ROOT-- level debug

Use the ongl command

In addition, Arthas supports the use of ognl to modify the log level. But this method is not friendly to log4j, and the modification will report an error. And even the supported logback/slf4j requires complex commands like ognl-c @ org.slf4j.LoggerFactory@getLogger ("root"). SetLevel () to modify it, which is not a good idea.

Online practice: printing MyBatis SQL statements in real time

Start arthas in the container

My online container does not have public network access (this is quite common). I will decompress all the packages and run them in the container:

Print SQL logs at DEBUG level

The following figure shows a request log without DEBUG information. You can see the interceptor information (INFO level) with only input and output parameters:

Use logger-- name ROOT-- level debug to output the SQL statement:

After all, many times online bug is caused by accidental misspelling of SQL.

At this point, the study of "how to dynamically modify the Logger level of online troubleshooting skills" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report