001
002package io.vrap.rmf.base.client.http;
003
004import java.util.Map;
005
006import io.vrap.rmf.base.client.ApiHttpHeaders;
007
008import org.slf4j.event.Level;
009
010/**
011 * Middleware instrumenting the {@link InternalLogger}
012 *
013 * <p>Responses are logged by default with {@link Level#INFO}.
014 * In case of an {@link ApiHttpHeaders#X_DEPRECATION_NOTICE deprecation} header the notice will be logged with {@link Level#INFO}
015 * Any exception will be logged with {@link Level#ERROR}</p>
016 *
017 * <p>The response, deprecation and error logger levels are configurable. Additionally, a map can be provided with the key a throwable type class
018 * and the value of the log level the exception should be logged with</p>
019 *
020 * <p>The middleware logs with debug also the request and the whole response including headers. With trace level the request and response will
021 * be logged pretty printed.</p>
022 *
023 * <p>All log events are written as lambda function to avoid rendering the message if the respective level is not enabled.</p>
024 */
025public interface InternalLoggerMiddleware extends Middleware {
026
027    static InternalLoggerMiddleware of(final InternalLoggerFactory internalLoggerFactory) {
028        return new InternalLoggerMiddlewareImpl(internalLoggerFactory);
029    }
030
031    static InternalLoggerMiddleware of(final InternalLoggerFactory internalLoggerFactory, final Level responseLogEvent,
032            final Level deprecationLogEvent) {
033        return new InternalLoggerMiddlewareImpl(internalLoggerFactory, responseLogEvent, deprecationLogEvent);
034    }
035
036    static InternalLoggerMiddleware of(final InternalLoggerFactory internalLoggerFactory, final Level responseLogEvent,
037            final Level deprecationLogEvent, final Level defaultExceptionLogEvent,
038            final Map<Class<? extends Throwable>, Level> exceptionLogEvents) {
039        return new InternalLoggerMiddlewareImpl(internalLoggerFactory, responseLogEvent, deprecationLogEvent,
040            defaultExceptionLogEvent, exceptionLogEvents);
041    }
042}