Class LoggingInterceptor

  • All Implemented Interfaces:
    okhttp3.Interceptor

    public class LoggingInterceptor
    extends Object
    implements okhttp3.Interceptor
    An OkHttp interceptor that handles logging of HTTP requests and responses.
    • Constructor Detail

      • LoggingInterceptor

        public LoggingInterceptor​(LogLevel logLevel)
        Creates an interceptor with a LogLevel enum.
        Parameters:
        logLevel - the level of traffic to log
    • Method Detail

      • log

        protected void log​(org.slf4j.Logger logger,
                           String s)
        Process the log using an SLF4j logger and an HTTP message.
        Parameters:
        logger - the SLF4j logger with the context of the request
        s - the message for logging
      • intercept

        public okhttp3.Response intercept​(okhttp3.Interceptor.Chain chain)
                                   throws IOException
        Specified by:
        intercept in interface okhttp3.Interceptor
        Throws:
        IOException
      • logLevel

        public LogLevel logLevel()
        Returns:
        the current logging level.
      • withLogLevel

        public LoggingInterceptor withLogLevel​(LogLevel logLevel)
        Sets the current logging level.
        Parameters:
        logLevel - the new logging level
        Returns:
        the interceptor