日志适配扩展

扩展说明

日志输出适配扩展点。

扩展接口

org.apache.dubbo.common.logger.LoggerAdapter

扩展配置

  1. <dubbo:application logger="xxx" />

或者:

  1. -Ddubbo:application.logger=xxx

已知扩展

  • org.apache.dubbo.common.logger.slf4j.Slf4jLoggerAdapter
  • org.apache.dubbo.common.logger.jcl.JclLoggerAdapter
  • org.apache.dubbo.common.logger.log4j.Log4jLoggerAdapter
  • org.apache.dubbo.common.logger.log4j2.Log4j2LoggerAdapter
  • org.apache.dubbo.common.logger.jdk.JdkLoggerAdapter

扩展示例

Maven 项目结构:

  1. src
  2. |-main
  3. |-java
  4. |-com
  5. |-xxx
  6. |-XxxLoggerAdapter.java (实现LoggerAdapter接口)
  7. |-resources
  8. |-META-INF
  9. |-dubbo
  10. |-org.apache.dubbo.common.logger.LoggerAdapter (纯文本文件,内容为:xxx=com.xxx.XxxLoggerAdapter)

XxxLoggerAdapter.java:

  1. package com.xxx;
  2. import org.apache.dubbo.common.logger.LoggerAdapter;
  3. public class XxxLoggerAdapter implements LoggerAdapter {
  4. public Logger getLogger(URL url) {
  5. // ...
  6. }
  7. }

XxxLogger.java:

  1. package com.xxx;
  2. import org.apache.dubbo.common.logger.Logger;
  3. public class XxxLogger implements Logger {
  4. public XxxLogger(URL url) {
  5. // ...
  6. }
  7. public void info(String msg) {
  8. // ...
  9. }
  10. // ...
  11. }

META-INF/dubbo/org.apache.dubbo.common.logger.LoggerAdapter:

  1. xxx=com.xxx.XxxLoggerAdapter

最后修改 September 21, 2021: Bug fix miss mialbox (#953) (57cf51b)