logger

查看logger信息,更新logger level

使用参考

查看所有logger信息

以下面的logback.xml为例:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration>
  3. <appender name="APPLICATION" class="ch.qos.logback.core.rolling.RollingFileAppender">
  4. <file>app.log</file>
  5. <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
  6. <fileNamePattern>mylog-%d{yyyy-MM-dd}.%i.txt</fileNamePattern>
  7. <maxFileSize>100MB</maxFileSize>
  8. <maxHistory>60</maxHistory>
  9. <totalSizeCap>2GB</totalSizeCap>
  10. </rollingPolicy>
  11. <encoder>
  12. <pattern>%logger{35} - %msg%n</pattern>
  13. </encoder>
  14. </appender>
  15. <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
  16. <appender-ref ref="APPLICATION" />
  17. </appender>
  18. <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
  19. <encoder>
  20. <pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n
  21. </pattern>
  22. <charset>utf8</charset>
  23. </encoder>
  24. </appender>
  25. <root level="INFO">
  26. <appender-ref ref="CONSOLE" />
  27. <appender-ref ref="ASYNC" />
  28. </root>
  29. </configuration>

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

  1. [arthas@2062]$ logger
  2. name ROOT
  3. class ch.qos.logback.classic.Logger
  4. classLoader sun.misc.Launcher$AppClassLoader@2a139a55
  5. classLoaderHash 2a139a55
  6. level INFO
  7. effectiveLevel INFO
  8. additivity true
  9. codeSource file:/Users/hengyunabc/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar
  10. appenders name CONSOLE
  11. class ch.qos.logback.core.ConsoleAppender
  12. classLoader sun.misc.Launcher$AppClassLoader@2a139a55
  13. classLoaderHash 2a139a55
  14. target System.out
  15. name APPLICATION
  16. class ch.qos.logback.core.rolling.RollingFileAppender
  17. classLoader sun.misc.Launcher$AppClassLoader@2a139a55
  18. classLoaderHash 2a139a55
  19. file app.log
  20. name ASYNC
  21. class ch.qos.logback.classic.AsyncAppender
  22. classLoader sun.misc.Launcher$AppClassLoader@2a139a55
  23. classLoaderHash 2a139a55
  24. appenderRef [APPLICATION]

appenders的信息里,可以看到

  • CONSOLE logger的target是System.out
  • APPLICATION logger是RollingFileAppender,它的file是app.log
  • ASYNC它的appenderRefAPPLICATION,即异步输出到文件里

查看指定名字的logger信息

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

查看指定classloader的logger信息

  1. [arthas@2062]$ logger -c 2a139a55
  2. name ROOT
  3. class ch.qos.logback.classic.Logger
  4. classLoader sun.misc.Launcher$AppClassLoader@2a139a55
  5. classLoaderHash 2a139a55
  6. level DEBUG
  7. effectiveLevel DEBUG
  8. additivity true
  9. codeSource file:/Users/hengyunabc/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar
  10. appenders name CONSOLE
  11. class ch.qos.logback.core.ConsoleAppender
  12. classLoader sun.misc.Launcher$AppClassLoader@2a139a55
  13. classLoaderHash 2a139a55
  14. target System.out
  15. name APPLICATION
  16. class ch.qos.logback.core.rolling.RollingFileAppender
  17. classLoader sun.misc.Launcher$AppClassLoader@2a139a55
  18. classLoaderHash 2a139a55
  19. file app.log
  20. name ASYNC
  21. class ch.qos.logback.classic.AsyncAppender
  22. classLoader sun.misc.Launcher$AppClassLoader@2a139a55
  23. classLoaderHash 2a139a55
  24. appenderRef [APPLICATION]

更新logger level

  1. [arthas@2062]$ logger --name ROOT --level debug
  2. update logger level success.

查看没有appender的logger的信息

默认情况下,logger命令只打印有appender的logger的信息。如果想查看没有appender的logger的信息,可以加上参数--include-no-appender

注意,通常输出结果会很长。

  1. [arthas@2062]$ logger --include-no-appender
  2. name ROOT
  3. class ch.qos.logback.classic.Logger
  4. classLoader sun.misc.Launcher$AppClassLoader@2a139a55
  5. classLoaderHash 2a139a55
  6. level DEBUG
  7. effectiveLevel DEBUG
  8. additivity true
  9. codeSource file:/Users/hengyunabc/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar
  10. appenders name CONSOLE
  11. class ch.qos.logback.core.ConsoleAppender
  12. classLoader sun.misc.Launcher$AppClassLoader@2a139a55
  13. classLoaderHash 2a139a55
  14. target System.out
  15. name APPLICATION
  16. class ch.qos.logback.core.rolling.RollingFileAppender
  17. classLoader sun.misc.Launcher$AppClassLoader@2a139a55
  18. classLoaderHash 2a139a55
  19. file app.log
  20. name ASYNC
  21. class ch.qos.logback.classic.AsyncAppender
  22. classLoader sun.misc.Launcher$AppClassLoader@2a139a55
  23. classLoaderHash 2a139a55
  24. appenderRef [APPLICATION]
  25. name com
  26. class ch.qos.logback.classic.Logger
  27. classLoader sun.misc.Launcher$AppClassLoader@2a139a55
  28. classLoaderHash 2a139a55
  29. level null
  30. effectiveLevel DEBUG
  31. additivity true
  32. codeSource file:/Users/hengyunabc/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar
  33. name com.alibaba
  34. class ch.qos.logback.classic.Logger
  35. classLoader sun.misc.Launcher$AppClassLoader@2a139a55
  36. classLoaderHash 2a139a55
  37. level null
  38. effectiveLevel DEBUG
  39. additivity true
  40. codeSource file:/Users/hengyunabc/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar
  41. ...