Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ihsanbal/LoggingInterceptor
An OkHttp interceptor which has pretty logger for request and response. +Mock support
https://github.com/ihsanbal/LoggingInterceptor
android interceptor java java-library kotlin logging-library logginginterceptor mock mocking-framework okhttp
Last synced: 3 months ago
JSON representation
An OkHttp interceptor which has pretty logger for request and response. +Mock support
- Host: GitHub
- URL: https://github.com/ihsanbal/LoggingInterceptor
- Owner: ihsanbal
- License: mit
- Created: 2017-02-22T17:56:10.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-02-13T14:21:04.000Z (9 months ago)
- Last Synced: 2024-05-02T03:05:28.737Z (6 months ago)
- Topics: android, interceptor, java, java-library, kotlin, logging-library, logginginterceptor, mock, mocking-framework, okhttp
- Language: Kotlin
- Homepage:
- Size: 32.6 MB
- Stars: 1,312
- Watchers: 30
- Forks: 104
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-android - LoggingInterceptor - An OkHttp interceptor which pretty logs request and response data. (Libraries / Logger)
- awesome-android-libraries - LoggingInterceptor
- awesome-android-libraries - LoggingInterceptor
- awesome-kotlin - LoggingInterceptor - An OkHttp interceptor which has pretty logger for request and response. +Mock support (Libraries)
- awesome-android - LoggingInterceptor - An OkHttp interceptor which pretty logs request and response data. (Libraries / Logger)
- awesome-android-libraries - LoggingInterceptor
README
LoggingInterceptor - Interceptor for [OkHttp3](https://github.com/square/okhttp) with pretty logger
--------[![Build Status](https://travis-ci.org/ihsanbal/LoggingInterceptor.svg?branch=master)](https://travis-ci.org/ihsanbal/LoggingInterceptor)
[![](https://img.shields.io/badge/AndroidWeekly-%23272-blue.svg?style=flat-square)](http://androidweekly.net/issues/issue-272)
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-LoggingInterceptor-green.svg?style=flat-square)](https://android-arsenal.com/details/1/5870)
[![API](https://img.shields.io/badge/API-9%2B-brightgreen.svg?style=flat-square)](http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html)
[![](https://jitpack.io/v/ihsanbal/LoggingInterceptor.svg)](https://jitpack.io/#ihsanbal/LoggingInterceptor)
[![SwaggerUI](https://img.shields.io/badge/Swagger-mockable.io-orange.svg?style=flat-square)](https://www.mockable.io/swagger/index.html?url=https%3A%2F%2Fdemo2961085.mockable.io%3Fopenapi#!/demo2961085)
Usage
--------```kotlin
val client = OkHttpClient.Builder()
client.addInterceptor(LoggingInterceptor.Builder()
.setLevel(Level.BASIC)
.log(VERBOSE)
.addHeader("cityCode","53")
.addQueryParam("moonStatus", "crescent")
.build())
```Download
--------Gradle:
Groovy
```groovy
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}dependencies {
implementation('com.github.ihsanbal:LoggingInterceptor:3.1.0') {
exclude group: 'org.json', module: 'json'
}
}
```kotlin DSL
```
allprojects {
repositories {
maven { setUrl("https://jitpack.io") }
}
}dependencies {
implementation("com.github.ihsanbal:LoggingInterceptor:3.1.0") {
exclude(group = "org.json", module = "json")
}
}```
Maven:
```xmljitpack.io
https://jitpack.iocom.github.ihsanbal
LoggingInterceptor
3.1.0```
Logger & Mock Support
---------------------
```kotlin
LoggingInterceptor.Builder()
//Add logger to print log as plain text
.logger(object : Logger {
override fun log(level: Int, tag: String?, msg: String?) {
Log.e("$tag - $level", "$msg")
}
})
//Enable mock for develop app with mock data
.enableMock(BuildConfig.MOCK, 1000L, object : BufferListener {
override fun getJsonResponse(request: Request?): String? {
val segment = request?.url?.pathSegments?.getOrNull(0)
return mAssetManager.open(String.format("mock/%s.json", segment)).source().buffer().readUtf8()
}
})
```Level
--------```kotlin
setLevel(Level.BASIC)
.NONE // No logs
.BASIC // Logging url,method,headers and body.
.HEADERS // Logging headers
.BODY // Logging body
```Platform - [Platform](https://github.com/square/okhttp/blob/master/okhttp/src/main/java/okhttp3/internal/platform/Platform.java)
--------```kotlin
log(Platform.WARN) // setting log type
```Tag
--------```kotlin
tag("LoggingI") // Request & response each log tag
request("request") // Request log tag
response("response") // Response log tag```
Header - [Recipes](https://github.com/square/okhttp/wiki/Recipes)
--------```kotlin
addHeader("token", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 ") // Adding to request
```Notes
--------
Some tips about log at this blog post: [“The way to get faster on development.”](https://medium.com/@ihsanbal/the-way-to-get-faster-on-development-9d7b23ef8c10)Also use the filter & configure logcat header for a better result