日志框架运行时管理

在 Dubbo 中运行时动态切换使用的日志框架

日志框架运行时管理

3.0.10 开始,dubbo-qos 运行时管控支持查询日志配置以及动态修改使用的日志框架和日志级别。

注:通过 dubbo-qos 修改的日志配置不进行持久化存储,在应用重启后将会失效。

1. 查询日志配置

命令:loggerInfo

示例:

  1. > telnet 127.0.0.1 22222
  2. > loggerInfo

输出:

  1. Trying 127.0.0.1...
  2. Connected to localhost.
  3. Escape character is '^]'.
  4. ___ __ __ ___ ___ ____
  5. / _ \ / / / // _ ) / _ ) / __ \
  6. / // // /_/ // _ |/ _ |/ /_/ /
  7. /____/ \____//____//____/ \____/
  8. dubbo>loggerInfo
  9. Available logger adapters: [jcl, jdk, log4j, slf4j]. Current Adapter: [log4j]. Log level: INFO

2. 修改日志级别

命令:switchLogLevel {level}

level: ALL, TRACE, DEBUG, INFO, WARN, ERROR, OFF

示例:

  1. > telnet 127.0.0.1 22222
  2. > switchLogLevel WARN

输出:

  1. Trying 127.0.0.1...
  2. Connected to localhost.
  3. Escape character is '^]'.
  4. ___ __ __ ___ ___ ____
  5. / _ \ / / / // _ ) / _ ) / __ \
  6. / // // /_/ // _ |/ _ |/ /_/ /
  7. /____/ \____//____//____/ \____/
  8. dubbo>loggerInfo
  9. Available logger adapters: [jcl, jdk, log4j, slf4j]. Current Adapter: [log4j]. Log level: INFO
  10. dubbo>switchLogLevel WARN
  11. OK
  12. dubbo>loggerInfo
  13. Available logger adapters: [jcl, jdk, log4j, slf4j]. Current Adapter: [log4j]. Log level: WARN
  1. ### 3\. 修改日志输出框架
  2. 命令:`switchLogger {loggerAdapterName}`
  3. loggerAdapterName: `slf4j`, `jcl`, `log4j`, `jdk`, `log4j2`
  4. 示例:

telnet 127.0.0.1 22222 switchLogger slf4j ```

输出:

  1. Trying 127.0.0.1...
  2. Connected to localhost.
  3. Escape character is '^]'.
  4. ___ __ __ ___ ___ ____
  5. / _ \ / / / // _ ) / _ ) / __ \
  6. / // // /_/ // _ |/ _ |/ /_/ /
  7. /____/ \____//____//____/ \____/
  8. dubbo>loggerInfo
  9. Available logger adapters: [jcl, slf4j, log4j, jdk]. Current Adapter: [log4j]. Log level: INFO
  10. dubbo>switchLogger slf4j
  11. OK
  12. dubbo>loggerInfo
  13. Available logger adapters: [jcl, slf4j, log4j, jdk]. Current Adapter: [slf4j]. Log level: INFO

最后修改 December 16, 2022: Fix check (#1736) (97972c1)