All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.permit.sdk.api.HttpLoggingInterceptor Maven / Gradle / Ivy

There is a newer version: 983f46e
Show newest version
package io.permit.sdk.api;

import io.permit.sdk.PermitConfig;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;

public class HttpLoggingInterceptor implements Interceptor {
    private final Logger logger;
    private final PermitConfig config;

    public HttpLoggingInterceptor(Logger logger, PermitConfig config) {
        this.logger = logger;
        this.config = config;
    }

    @NotNull
    @Override public Response intercept(Interceptor.Chain chain) throws IOException {
        Request request = chain.request();

        if (config.isDebugMode()) {
            logger.info(
                    String.format(
                            "[Permit SDK] Sending HTTP request: %s %s", request.method(), request.url()
                    )
            );
        }

        Response response = chain.proceed(request);

        if (config.isDebugMode()) {
            logger.info(
                    String.format(
                            "[Permit SDK] Received HTTP response: %s %s, status %d", request.method(), request.url(), response.code()
                    )
            );
        }

        return response;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy