{"id":3568,"url":"https://github.com/ihsanbal/LoggingInterceptor","last_synced_at":"2025-08-03T20:32:48.071Z","repository":{"id":43445059,"uuid":"82835649","full_name":"ihsanbal/LoggingInterceptor","owner":"ihsanbal","description":"An OkHttp interceptor which has pretty logger for request and response. +Mock support","archived":false,"fork":false,"pushed_at":"2024-02-13T14:21:04.000Z","size":34138,"stargazers_count":1326,"open_issues_count":1,"forks_count":112,"subscribers_count":30,"default_branch":"master","last_synced_at":"2024-11-21T03:51:49.587Z","etag":null,"topics":["android","interceptor","java","java-library","kotlin","logging-library","logginginterceptor","mock","mocking-framework","okhttp"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ihsanbal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-22T17:56:10.000Z","updated_at":"2024-11-14T16:24:02.000Z","dependencies_parsed_at":"2024-01-02T21:21:10.244Z","dependency_job_id":"be458701-5e01-42de-858d-b8a1ef00ffaf","html_url":"https://github.com/ihsanbal/LoggingInterceptor","commit_stats":null,"previous_names":[],"tags_count":98,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ihsanbal%2FLoggingInterceptor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ihsanbal%2FLoggingInterceptor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ihsanbal%2FLoggingInterceptor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ihsanbal%2FLoggingInterceptor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ihsanbal","download_url":"https://codeload.github.com/ihsanbal/LoggingInterceptor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228567009,"owners_count":17937983,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","interceptor","java","java-library","kotlin","logging-library","logginginterceptor","mock","mocking-framework","okhttp"],"created_at":"2024-01-05T20:16:45.181Z","updated_at":"2024-12-07T05:30:41.247Z","avatar_url":"https://github.com/ihsanbal.png","language":"Kotlin","readme":"LoggingInterceptor - Interceptor for [OkHttp3](https://github.com/square/okhttp) with pretty logger\n--------\n\n[![Build Status](https://travis-ci.org/ihsanbal/LoggingInterceptor.svg?branch=master)](https://travis-ci.org/ihsanbal/LoggingInterceptor)\n[![](https://img.shields.io/badge/AndroidWeekly-%23272-blue.svg?style=flat-square)](http://androidweekly.net/issues/issue-272)\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-LoggingInterceptor-green.svg?style=flat-square)](https://android-arsenal.com/details/1/5870)\n[![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)\n[![](https://jitpack.io/v/ihsanbal/LoggingInterceptor.svg)](https://jitpack.io/#ihsanbal/LoggingInterceptor)\n[![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)\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/ihsanbal/LoggingInterceptor/blob/master/images/logcat.png\"/\u003e\n\u003c/p\u003e\n\nUsage\n--------\n\n```kotlin\nval client = OkHttpClient.Builder()\n    client.addInterceptor(LoggingInterceptor.Builder()\n             .setLevel(Level.BASIC)\n             .log(VERBOSE)\n             .addHeader(\"cityCode\",\"53\")\n             .addQueryParam(\"moonStatus\", \"crescent\")\n             .build())\n```\n\nDownload\n--------\n\nGradle:\n\nGroovy\n```groovy\nallprojects {\n\trepositories {\n\t\tmaven { url 'https://jitpack.io' }\n\t}\n}\n\ndependencies {\n\timplementation('com.github.ihsanbal:LoggingInterceptor:3.1.0') {\n        \texclude group: 'org.json', module: 'json'\n    \t}\n}\n```\n\nkotlin DSL\n```\nallprojects {\n\trepositories {\n\t\tmaven { setUrl(\"https://jitpack.io\") }\n\t}\n}\n\n\ndependencies {\n\timplementation(\"com.github.ihsanbal:LoggingInterceptor:3.1.0\") {\n        \texclude(group = \"org.json\", module = \"json\")\n    \t}\n}\n\n```\n\nMaven:\n```xml\n\u003crepository\u003e\n   \u003cid\u003ejitpack.io\u003c/id\u003e\n   \u003curl\u003ehttps://jitpack.io\u003c/url\u003e\n\u003c/repository\u003e\n\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.ihsanbal\u003c/groupId\u003e\n    \u003cartifactId\u003eLoggingInterceptor\u003c/artifactId\u003e\n    \u003cversion\u003e3.1.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n\nLogger \u0026 Mock Support\n---------------------\n```kotlin\nLoggingInterceptor.Builder()\n    //Add logger to print log as plain text\n    .logger(object : Logger {\n          override fun log(level: Int, tag: String?, msg: String?) {\n              Log.e(\"$tag - $level\", \"$msg\")\n          }\n      })\n      //Enable mock for develop app with mock data\n      .enableMock(BuildConfig.MOCK, 1000L, object : BufferListener {\n          override fun getJsonResponse(request: Request?): String? {\n              val segment = request?.url?.pathSegments?.getOrNull(0)\n              return mAssetManager.open(String.format(\"mock/%s.json\", segment)).source().buffer().readUtf8()\n          }\n      })\n```\t\n\nLevel\n--------\n\n```kotlin\nsetLevel(Level.BASIC)\n\t      .NONE // No logs\n\t      .BASIC // Logging url,method,headers and body.\n\t      .HEADERS // Logging headers\n\t      .BODY // Logging body\n```\t\n\nPlatform - [Platform](https://github.com/square/okhttp/blob/master/okhttp/src/main/java/okhttp3/internal/platform/Platform.java)\n--------\n\n```kotlin\nlog(Platform.WARN) // setting log type\n```\n\nTag\n--------\n\n```kotlin\ntag(\"LoggingI\") // Request \u0026 response each log tag\nrequest(\"request\") // Request log tag\nresponse(\"response\") // Response log tag\n\n```\n\t\nHeader - [Recipes](https://github.com/square/okhttp/wiki/Recipes)\n--------\n\n```kotlin\naddHeader(\"token\", \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 \") // Adding to request\n```\n\nNotes\n--------\nSome 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)\n\nAlso use the filter \u0026 configure logcat header for a better result\n\n\u003cp align=\"left\"\u003e\n    \u003cimg src=\"https://github.com/ihsanbal/LoggingInterceptor/blob/master/images/screen_shot_5.png\" width=\"280\" height=\"155\"/\u003e\n    \u003cimg src=\"https://github.com/ihsanbal/LoggingInterceptor/blob/master/images/screen_shot_4.png\" width=\"280\" height=\"155\"/\u003e\n\u003c/p\u003e\n","funding_links":[],"categories":["Logger","Libraries","测试"],"sub_categories":["Logger"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fihsanbal%2FLoggingInterceptor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fihsanbal%2FLoggingInterceptor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fihsanbal%2FLoggingInterceptor/lists"}