中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Java如何使用arthas修改日志級別

發布時間:2022-06-17 11:55:10 來源:億速云 閱讀:276 作者:iii 欄目:開發技術

這篇文章主要講解了“Java如何使用arthas修改日志級別”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“Java如何使用arthas修改日志級別”吧!

    arthas能夠更改日志的級別,下面是logger的用法

    查看logger信息,更新logger level

    查看所有logger信息 logger

    以下面的logback.xml為例:

    <?xml version="1.0" encoding="UTF-8"?><configuration>    <appender name="APPLICATION" class="ch.qos.logback.core.rolling.RollingFileAppender">        <file>app.log</file>        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">            <fileNamePattern>mylog-%d{yyyy-MM-dd}.%i.txt</fileNamePattern>            <maxFileSize>100MB</maxFileSize>            <maxHistory>60</maxHistory>            <totalSizeCap>2GB</totalSizeCap>        </rollingPolicy>        <encoder>            <pattern>%logger{35} - %msg%n</pattern>        </encoder>    </appender>     <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">        <appender-ref ref="APPLICATION" />    </appender>     <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">        <encoder>            <pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n            </pattern>            <charset>utf8</charset>        </encoder>    </appender>     <root level="INFO">        <appender-ref ref="CONSOLE" />        <appender-ref ref="ASYNC" />    </root></configuration>

    sc -d *FormulaEngine |grepclassLoaderHash

    sc -d FormulaEngine.class*

    使用logger命令打印的結果是:

    [arthas@2062]$ logger name                                   ROOT class                                  ch.qos.logback.classic.Logger classLoader                            sun.misc.Launcher$AppClassLoader@2a139a55 classLoaderHash                        2a139a55 level                                  INFO effectiveLevel                         INFO additivity                             true codeSource                             file:/Users/hengyunabc/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar appenders                              name            CONSOLE                                        class           ch.qos.logback.core.ConsoleAppender                                        classLoader     sun.misc.Launcher$AppClassLoader@2a139a55                                        classLoaderHash 2a139a55                                        target          System.out                                        name            APPLICATION                                        class           ch.qos.logback.core.rolling.RollingFileAppender                                        classLoader     sun.misc.Launcher$AppClassLoader@2a139a55                                        classLoaderHash 2a139a55                                        file            app.log                                        name            ASYNC                                        class           ch.qos.logback.classic.AsyncAppender                                        classLoader     sun.misc.Launcher$AppClassLoader@2a139a55                                        classLoaderHash 2a139a55                                        appenderRef     [APPLICATION]

    appenders的信息里,可以看到

    CONSOLElogger的target是System.out

    APPLICATIONlogger是RollingFileAppender,它的file是app.log

    ASYNC它的appenderRefAPPLICATION,即異步輸出到文件里

    Java如何使用arthas修改日志級別

    查看指定名字的logger信息 logger -n org.springframework.web

    [arthas@2062]$ logger -n org.springframework.web name                                   org.springframework.web class                                  ch.qos.logback.classic.Logger classLoader                            sun.misc.Launcher$AppClassLoader@2a139a55 classLoaderHash                        2a139a55 level                                  null effectiveLevel                         INFO additivity                             true codeSource                             file:/Users/hengyunabc/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar

    查看指定classloader的logger信息

    注意hashcode是變化的,需要先查看當前的ClassLoader信息,提取對應ClassLoader的hashcode。

    如果你使用-c,你需要手動輸入hashcode:-c <hashcode>

    [arthas@2062]$ logger -c 2a139a55 name                                   ROOT class                                  ch.qos.logback.classic.Logger classLoader                            sun.misc.Launcher$AppClassLoader@2a139a55 classLoaderHash                        2a139a55 level                                  DEBUG effectiveLevel                         DEBUG additivity                             true codeSource                             file:/Users/hengyunabc/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar appenders                              name            CONSOLE                                        class           ch.qos.logback.core.ConsoleAppender                                        classLoader     sun.misc.Launcher$AppClassLoader@2a139a55                                        classLoaderHash 2a139a55                                        target          System.out                                        name            APPLICATION                                        class           ch.qos.logback.core.rolling.RollingFileAppender                                        classLoader     sun.misc.Launcher$AppClassLoader@2a139a55                                        classLoaderHash 2a139a55                                        file            app.log                                        name            ASYNC                                        class           ch.qos.logback.classic.AsyncAppender                                        classLoader     sun.misc.Launcher$AppClassLoader@2a139a55                                        classLoaderHash 2a139a55                                        appenderRef     [APPLICATION]

    對于只有唯一實例的ClassLoader可以通過--classLoaderClass指定class name,使用起來更加方便:

    logger --classLoaderClass sun.misc.Launcher$AppClassLoader

    注: 這里classLoaderClass 在 java 8 是 sun.misc.Launcher$AppClassLoader,而java 11的classloader是jdk.internal.loader.ClassLoaders$AppClassLoader。

    --classLoaderClass的值是ClassLoader的類名,只有匹配到唯一的ClassLoader實例時才能工作,目的是方便輸入通用命令,而-c <hashcode>是動態變化的。

    更新logger level 找到需要修改日志級別的類

    命令:

    sc -d FreeResourceQueryActionImpl.class*

    或者

    sc -d *FreeResourceQueryActionImpl | grep classLoaderHash

    結果:目的就是為了找出classLoaderHash

    修改

    [arthas@2062]$ logger --name ROOT --level debugupdate logger level success.

    Java如何使用arthas修改日志級別

    Java如何使用arthas修改日志級別指定classloader更新 logger level

    默認情況下,logger命令會在SystemClassloader下執行,如果應用是傳統的war應用,或者spring boot fat jar啟動的應用,那么需要指定classloader。

    可以先用sc -d yourClassName來查看具體的 classloader hashcode,然后在更新level時指定classloader:

    [arthas@2062]$ logger -c 2a139a55 --name ROOT --level debug

    查看沒有appender的logger的信息

    默認情況下,logger命令只打印有appender的logger的信息。如果想查看沒有appender的logger的信息,可以加上參數--include-no-appender

    注意,通常輸出結果會很長。

    [arthas@2062]$ logger --include-no-appender name                                   ROOT class                                  ch.qos.logback.classic.Logger classLoader                            sun.misc.Launcher$AppClassLoader@2a139a55 classLoaderHash                        2a139a55 level                                  DEBUG effectiveLevel                         DEBUG additivity                             true codeSource                             file:/Users/hengyunabc/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar appenders                              name            CONSOLE                                        class           ch.qos.logback.core.ConsoleAppender                                        classLoader     sun.misc.Launcher$AppClassLoader@2a139a55                                        classLoaderHash 2a139a55                                        target          System.out                                        name            APPLICATION                                        class           ch.qos.logback.core.rolling.RollingFileAppender                                        classLoader     sun.misc.Launcher$AppClassLoader@2a139a55                                        classLoaderHash 2a139a55                                        file            app.log                                        name            ASYNC                                        class           ch.qos.logback.classic.AsyncAppender                                        classLoader     sun.misc.Launcher$AppClassLoader@2a139a55                                        classLoaderHash 2a139a55                                        appenderRef     [APPLICATION]  name                                   com class                                  ch.qos.logback.classic.Logger classLoader                            sun.misc.Launcher$AppClassLoader@2a139a55 classLoaderHash                        2a139a55 level                                  null effectiveLevel                         DEBUG additivity                             true codeSource                             file:/Users/hengyunabc/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar  name                                   com.alibaba class                                  ch.qos.logback.classic.Logger classLoader                            sun.misc.Launcher$AppClassLoader@2a139a55 classLoaderHash                        2a139a55 level                                  null effectiveLevel                         DEBUG additivity                             true codeSource                             file:/Users/hengyunabc/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar...

    退出arthas

    為了不影響性能,解決完問題需要退出arthas

    如果只是退出當前的連接,可以用quit或者exit命令。Attach到目標進程上的arthas還會繼續運行,端口會保持開放,下次連接時可以直接連接上。

    如果想完全退出arthas,可以執行stop命令。

    退出之前恢復原來的日志級別

    感謝各位的閱讀,以上就是“Java如何使用arthas修改日志級別”的內容了,經過本文的學習后,相信大家對Java如何使用arthas修改日志級別這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!

    向AI問一下細節

    免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

    AI

    永州市| 密山市| 渭南市| 吉林市| 江都市| 肇东市| 天水市| 塘沽区| 田阳县| 怀宁县| 涞水县| 巩义市| 西青区| 寿光市| 临西县| 栖霞市| 金沙县| 河北省| 辉南县| 都昌县| 西和县| 抚远县| 涟水县| 章丘市| 安陆市| 翁源县| 绥江县| 武定县| 两当县| 雅江县| 阳春市| 壤塘县| 昌乐县| 彰武县| 邵武市| 会理县| 漳浦县| 宜昌市| 大厂| 环江| 察隅县|