日志适配扩展

扩展说明

日志输出适配扩展点。

扩展接口

com.alibaba.dubbo.common.logger.LoggerAdapter

扩展配置

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

或者:

  1. -Ddubbo:application.logger=xxx

已知扩展

  • com.alibaba.dubbo.common.logger.slf4j.Slf4jLoggerAdapter
  • com.alibaba.dubbo.common.logger.jcl.JclLoggerAdapter
  • com.alibaba.dubbo.common.logger.log4j.Log4jLoggerAdapter
  • com.alibaba.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. |-com.alibaba.dubbo.common.logger.LoggerAdapter (纯文本文件,内容为:xxx=com.xxx.XxxLoggerAdapter)

XxxLoggerAdapter.java:

  1. package com.xxx;
  2. import com.alibaba.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 com.alibaba.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/com.alibaba.dubbo.common.logger.LoggerAdapter:

  1. xxx=com.xxx.XxxLoggerAdapter

原文: http://dubbo.apache.org/#!/docs/dev/impls/logger-adapter.md?lang=zh-cn