Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feign capabilities not support multiple feign.Logger Logger #2794

Open
ipanocloud opened this issue Feb 27, 2025 · 1 comment
Open

feign capabilities not support multiple feign.Logger Logger #2794

ipanocloud opened this issue Feb 27, 2025 · 1 comment

Comments

@ipanocloud
Copy link

ipanocloud commented Feb 27, 2025

feign.client.config.default.capabilities[0]=com.google.ACapability
feign.client.config.default.capabilities[1]=com.google.BCapability

this config.
code detail demo:

public class ACapability implements Capability {
   @Override
    public Logger enrich(Logger logger) {
        return new ALogger(logger);
    }
}

public class BCapability implements Capability {
    @Override
    public Logger enrich(CustomLogger logger) { 
        return new BLogger(logger);
    }
}

public class ALogger extends feign.Logger {

   @Override
    protected Response logAndRebufferResponse(String configKey, Level logLevel, Response response, long elapsedTime) {
         // todo print message
    }
}

public class BLogger extends feign.Logger {

   @Override
    protected Response logAndRebufferResponse(String configKey, Level logLevel, Response response, long elapsedTime) {
         // todo print message
    }
}

The only thing that will be effective is com.google.BCapability

@ipanocloud ipanocloud changed the title feign capabilities not support mulit Logger feign capabilities not support multiple feign.Logger Logger Feb 27, 2025
@hosuaby
Copy link
Contributor

hosuaby commented Mar 25, 2025

@ipanocloud This probably Spring Feign problem.

I wrote the following test and enrichment works as expected:

  @Test
  void multipleCapabilitiesEnrichment() {
    Feign.Builder builder =
        Feign.builder()
            .logger(new Logger.JavaLogger(BaseBuilderTest.class))
            .addCapability(new ACapability())
            .addCapability(new BCapability())
            .enrich();

    assertThat(builder.logger).isInstanceOf(BLogger.class);
    assertThat(((BLogger) builder.logger).delegate).isInstanceOf(ALogger.class);
    assertThat(((ALogger) ((BLogger) builder.logger).delegate).delegate)
        .isInstanceOf(Logger.JavaLogger.class);
  }

  public class ACapability implements Capability {
    @Override
    public Logger enrich(Logger logger) {
      return new ALogger(logger);
    }
  }

  public class BCapability implements Capability {
    @Override
    public Logger enrich(Logger logger) {
      return new BLogger(logger);
    }
  }

  public class ALogger extends feign.Logger {
    Logger delegate;

    ALogger(Logger logger) {
      this.delegate = logger;
    }

    @Override
    protected void log(final String configKey, final String format, final Object... args) {
      // DO NOTHING
    }
  }

  public class BLogger extends feign.Logger {
    Logger delegate;

    BLogger(Logger logger) {
      this.delegate = logger;
    }

    @Override
    protected void log(final String configKey, final String format, final Object... args) {
      // DO NOTHING
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants