Skip to content

Instantly share code, notes, and snippets.

@jfuerth
Created March 12, 2018 14:53
Show Gist options
  • Save jfuerth/0c4a3dd9d7285941af55a6be76f315e2 to your computer and use it in GitHub Desktop.
Save jfuerth/0c4a3dd9d7285941af55a6be76f315e2 to your computer and use it in GitHub Desktop.
Recipe for adding an SLF4J TRACE-level logger to a Feign-OkHttp3 client
private static class TraceLogger implements okhttp3.logging.HttpLoggingInterceptor.Logger {
/*
.client(new OkHttpClient(new okhttp3.OkHttpClient.Builder()
.addInterceptor(new okhttp3.logging.HttpLoggingInterceptor(
new TraceLogger(LoggerFactory.getLogger(FEIGN_TARGET)))
.setLevel(HttpLoggingInterceptor.Level.BODY))
.build()))
*/
private final org.slf4j.Logger slf4jLogger;
private TraceLogger(org.slf4j.Logger slf4jLogger) {
this.slf4jLogger = slf4jLogger;
}
@Override
public void log(String message) {
slf4jLogger.trace(message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment