Giter Site home page Giter Site logo

avew / customizable-okhttp-logging-interceptor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bartek-wesolowski/customizable-okhttp-logging-interceptor

0.0 0.0 0.0 94 KB

An OkHttp interceptor which logs HTTP request and response data and allows output customization.

License: MIT License

Kotlin 100.00%

customizable-okhttp-logging-interceptor's Introduction

Customizable OkHttp Logging Interceptor

Maven Central example workflow

An OkHttp interceptor which logs HTTP request and response data and allows output customization. The implementation is based on the Logging Interceptor from OkHttp.

val loggingInterceptor = CustomizableHttpLoggingInterceptor(
    logHeaders = true,
    logBody = true,
    maxBodyLength = 1000L
)
val client = OkHttpClient.Builder()
    .addInterceptor(loggingInterceptor)
    .build()

To log to a custom location, pass a Logger instance to the constructor.

val loggingInterceptor = CustomizableHttpLoggingInterceptor(
    logger = { message -> Timber.tag("OkHttp").d(message) }
)

Warning: The logs generated by this interceptor when using the HEADERS or BODY levels have the potential to leak sensitive information such as "Authorization" or "Cookie" headers and the contents of request and response bodies. This data should only be logged in a controlled way or in a non-production environment.

You can redact headers that may contain sensitive information by calling redactHeader().

loggingInterceptor.redactHeader("Authorization")
loggingInterceptor.redactHeader("Cookie")

Installation

Customizable OkHttp Logging Interceptor is available on Maven Central. Add the following to your build.gradle/build.gradle.kts file:

Groovy DSL

testImplementation "io.github.bartek-wesolowski:customizable-okhttp-logging-interceptor:2.0.0"

Kotlin DSL

testImplementation("io.github.bartek-wesolowski:customizable-okhttp-logging-interceptor:2.0.0")

customizable-okhttp-logging-interceptor's People

Contributors

bartek-wesolowski avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.