Arthas 之查看和修改日志级别

logger 命令

方法介绍

查看 logger 信息,更新 logger level。

官方文档:https://alibaba.github.io/arthas/logger.html

帮助信息:

1597912401412

使用 logger 命令

修改默认日志级别

使用 logger 命令打印的结果是(默认 --name ROOT):

[arthas@23176]$ logger
 name                ROOT
 class               ch.qos.logback.classic.Logger
 classLoader         sun.misc.Launcher$AppClassLoader@73d16e93
 classLoaderHash     73d16e93
 level               INFO
 effectiveLevel      INFO
 additivity          true
 codeSource          file:/E:/code/Java/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@73d16e93
                     classLoaderHash 73d16e93
                     target          System.out
                     name            FILE
                     class           ch.qos.logback.core.rolling.RollingFileAppender
                     classLoader     sun.misc.Launcher$AppClassLoader@73d16e93
                     classLoaderHash 73d16e93
                     file            C:\Users\HZWEIY~1\AppData\Local\Temp\/spring.log
                     name            INFO_FILE
                     class           ch.qos.logback.core.rolling.RollingFileAppender
                     classLoader     sun.misc.Launcher$AppClassLoader@73d16e93
                     classLoaderHash 73d16e93
                     file            ../log/info.log
                     name            ERROR_FILE
                     class           ch.qos.logback.core.rolling.RollingFileAppender
                     classLoader     sun.misc.Launcher$AppClassLoader@73d16e93
                     classLoaderHash 73d16e93
                     file            ../log/error.log

修改日志级别为 debug

[arthas@23176]$ logger --name ROOT --level debug
Update logger level success.

修改方法日志级别

查看指定类的 logger 信息:

[arthas@23176]$ logger  -n sample.mybatis.mapper.CompanyMapper
 name                sample.mybatis.mapper.CompanyMapper
 class               ch.qos.logback.classic.Logger
 classLoader         sun.misc.Launcher$AppClassLoader@73d16e93
 classLoaderHash     73d16e93
 level               null
 effectiveLevel      DEBUG
 additivity          true
 codeSource          file:/E:/code/Java/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar

修改日志级别:

[arthas@23176]$ logger  -n sample.mybatis.mapper.CompanyMapper -l debug
Update logger level success.

使用 ongl 命令

修改默认日志级别

获取默认日志级别:

[arthas@23176]$ ognl '@org.slf4j.LoggerFactory@getLogger("root")'
@Logger[
    serialVersionUID=@Long[5454405123156820674],
    FQCN=@String[ch.qos.logback.classic.Logger],
    name=@String[ROOT],
    level=@Level[INFO],
    effectiveLevelInt=@Integer[20000],
    parent=null,
    childrenList=@CopyOnWriteArrayList[isEmpty=false;size=3],
    aai=@AppenderAttachableImpl[ch.qos.logback.core.spi.AppenderAttachableImpl@3a0771d0],
    additive=@Boolean[true],
    loggerContext=@LoggerContext[ch.qos.logback.classic.LoggerContext[default]],
]

修改日志级别为 debug

[arthas@23176]$ ognl '@org.slf4j.LoggerFactory@getLogger("root").setLevel(@ch.qos.logback.classic.Level@DEBUG)'
null

修改方法日志级别

获取方法日志级别:

[arthas@23176]$ ognl '@sample.mybatis.SampleXmlApplication@log'
@Logger[
    serialVersionUID=@Long[5454405123156820674],
    FQCN=@String[ch.qos.logback.classic.Logger],
    name=@String[sample.mybatis.SampleXmlApplication],
    level=null,
    effectiveLevelInt=@Integer[20000],
    parent=@Logger[Logger[sample.mybatis]],
    childrenList=null,
    aai=null,
    additive=@Boolean[true],
    loggerContext=@LoggerContext[ch.qos.logback.classic.LoggerContext[default]],
]

修改日志级别:

[arthas@23176]$ ognl '@sample.mybatis.SampleXmlApplication@log.setLevel(@ch.qos.logback.classic.Level@DEBUG)'
null

查看日志配置

[arthas@23176]$ ognl '@org.slf4j.LoggerFactory@getLogger("root").loggerContext.objectMap'
@HashMap[
    @String[EVALUATOR_MAP]:@HashMap[isEmpty=true;size=0],
    @String[RFA_FILENAME_PATTERN_COLLISION_MAP]:@HashMap[isEmpty=false;size=3],
    @String[PATTERN_RULE_REGISTRY]:@HashMap[isEmpty=false;size=3],
    @String[CONFIGURATION_WATCH_LIST]:@ConfigurationWatchList[ch.qos.logback.core.joran.spi.ConfigurationWatchList@68ec0e24],
    @String[org.springframework.boot.logging.LoggingSystem]:@Object[java.lang.Object@5336a68d],
    @String[RECONFIGURE_ON_CHANGE_TASK]:@ReconfigureOnChangeTask[ReconfigureOnChangeTask(born:1597910258119)],
    @String[FA_FILENAME_COLLISION_MAP]:@HashMap[isEmpty=false;size=3],
    @String[SAFE_JORAN_CONFIGURATION]:@ArrayList[isEmpty=false;size=135],
]

查看日志配置文件加载位置:

[arthas@23176]$ ognl '#map1=@org.slf4j.LoggerFactory@getLogger("root").loggerContext.objectMap, #map1.get("CONFIGURATION_WATCH_LIST")'
@ConfigurationWatchList[
    mainURL=@URL[file:/C:/Codes/JavaWorkSpace/workspace48/arthas-demo/target/classes/logback.xml],
    fileWatchList=@ArrayList[isEmpty=false;size=1],
    lastModifiedList=@ArrayList[isEmpty=false;size=1],
    noContextWarning=@Integer[0],
    context=@LoggerContext[ch.qos.logback.classic.LoggerContext[default]],
    declaredOrigin=@ConfigurationWatchList[ch.qos.logback.core.joran.spi.ConfigurationWatchList@68ec0e24],
]