{"id":13516422,"url":"https://github.com/simonpercic/OkLog","last_synced_at":"2025-03-31T06:31:03.445Z","repository":{"id":57722808,"uuid":"43640886","full_name":"simonpercic/OkLog","owner":"simonpercic","description":"Network logging interceptor for OkHttp. Logs an URL link with encoded network call data for every OkHttp call.","archived":false,"fork":false,"pushed_at":"2020-03-14T11:53:46.000Z","size":4253,"stargazers_count":493,"open_issues_count":3,"forks_count":23,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-01-03T09:39:14.126Z","etag":null,"topics":["android-library","logging","okhttp"],"latest_commit_sha":null,"homepage":"https://proandroiddev.com/oklog-2-0-improved-android-network-logging-a72b2ffe4c66","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/simonpercic.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-04T15:23:58.000Z","updated_at":"2024-10-03T08:36:17.000Z","dependencies_parsed_at":"2022-08-28T10:11:40.784Z","dependency_job_id":null,"html_url":"https://github.com/simonpercic/OkLog","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonpercic%2FOkLog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonpercic%2FOkLog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonpercic%2FOkLog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonpercic%2FOkLog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonpercic","download_url":"https://codeload.github.com/simonpercic/OkLog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246429459,"owners_count":20775805,"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-library","logging","okhttp"],"created_at":"2024-08-01T05:01:22.164Z","updated_at":"2025-03-31T06:30:58.420Z","avatar_url":"https://github.com/simonpercic.png","language":"Kotlin","readme":"# OkLog \nNetwork logging interceptor for OkHttp. \nLogs an URL link with encoded network call data for every OkHttp call.\n\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-OkLog-green.svg?style=true)](https://android-arsenal.com/details/1/3513)\n[![Build Status](https://api.travis-ci.org/simonpercic/OkLog.svg?branch=master)](https://travis-ci.org/simonpercic/OkLog)\n[ ![Download](https://api.bintray.com/packages/simonpercic/maven/oklog3/images/download.svg) ](https://bintray.com/simonpercic/maven/oklog3/_latestVersion)\n\n\n## Motivation\nDebugging Android responses should be easier. Even with Retrofit logging enabled, copying multi-line responses from logcat is cumbersome and annoying.\n\nOkLog writes a clickable link to the (Android) log with the OkHttp's response info as params. Clicking on the link in logcat opens your browser with the [detailed response info](#additional-log-data-options).\n\n![Example](https://raw.githubusercontent.com/simonpercic/OkLog/develop/art/oklog.gif)\n\n### Example response info\nSee an example [in action](http://oklog.responseecho.com/v1/r/H4sIAAAAAAAAAKtWykxRsjLVUcpLzE1VslIKKSpNVXBJLUlNLsksS1XSUSoqzSvJBEmZGQAVpZaU5xdlK1lVg7VZwLV5OPkr1dYCAB5WJYFNAAAA?qb=H4sIAAAAAAAAAKtWykvMTVWyUgopKk1VcEktSU0uySxLVdJRykstKc8vylayqlbKTFGysqjVUSoqzSvJBKk2M6gFAPS5LSY5AAAA\u0026d=H4sIAAAAAAAAAJ2SQW_TMBiGyYoGWBwmH6CCokUgJITiNi7p1hQhEaVhm7QkVeuhHXESq7WX2pET0vXKv-In8K9wQOIw7cTB38WP3-_1-32gt7gi0Ns0TTUbjSrNW9owlJ1muYeatt6oXU0rPjSH6j3aqvxmmKvtqLt48bh7NcJD_PqYVlXJc9pwJUeiVvKjnW-orlnz6Yp8QdN3_tT6_OD8l7V8FGpmOhTXPw--xeIIHK6YbpmGh6HaZWov-gCESkqWd1IQ3DBWIVrylolj0L9GwV8fSyNR8i1v0GVXYQ-PXfEGDO4BlmxLueRybSDsCxs8NfoNkw0i-4rBo7vODfEyyHNW16gDtSpRUJZqh1LN11xC671IwOBeImbNRhU1HKYLcpEmK-csIs55FMydRboijgnamUeXEYkcsgzCyAnTJIlCIgbg2R29mN6iYM3gAXbFB_D837eIprKmf7JBFwXsT6Zjt_DZZIIz38vczHVxkbknY_EWPJybCOCrWEnHdk_tRLX22MUnNvZn3mTmYfssJib_3ldO4RMzQ7tl6--6sm7jH9Z_rcNvtxQDp0oCAAA=).\n\n[![Example response info](https://raw.githubusercontent.com/simonpercic/OkLog/develop/art/oklog-response-thumb.png)](https://raw.githubusercontent.com/simonpercic/OkLog/develop/art/oklog-response.png)\n\n\n## How does it work?\nOkLog intercepts responses from OkHttp, it then gzips and Base64 encodes the network response \u0026 the detailed response info and generates an url link with the encoded data as params. It then logs the url using:\n- [Timber](https://github.com/JakeWharton/timber) OR\n- Android's built-in logger (if your project does not include Timber) OR\n- Java's Logger (if used in a pure-Java/Kotlin project) OR\n- your custom logger\n\nThat url points to a hosted instance of the [ResponseEcho](https://github.com/simonpercic/ResponseEcho) web app that does the exact opposite, i.e. Base64 decodes and unpacks the url params and displays the response info for easier debugging. \n\n\n## Usage\n\n### OkLog for OkHttp (use for Retrofit 1.x)\nAdd using Gradle:\n```groovy\ncompile 'com.github.simonpercic:oklog:2.3.0'\n```\n\nOR (for a pure-Java/Kotlin project, without dependencies on Android)\n\n```groovy\ncompile 'com.github.simonpercic:oklog-java:2.3.0'\n```\n\nusage:\n\n```java\n// create an instance of OkLogInterceptor using a builder()\nOkLogInterceptor okLogInterceptor = OkLogInterceptor.builder().build();\n\n// create an instance of OkHttpClient\nOkHttpClient okHttpClient = new OkHttpClient();\n\n// add OkLogInterceptor to OkHttpClient interceptors\nList\u003cInterceptor\u003e clientInterceptors = okHttpClient.interceptors();\nCollections.addAll(clientInterceptors, okLogInterceptor);\n```\n\n```java\n// use with Retrofit\nClient okClient = new OkClient(okHttpClient);\n\nnew RestAdapter.Builder()\n    .setEndpoint(endpoint)\n    .setClient(okClient)\n    ...\n    .build();\n```\n\n### OkLog3 for OkHttp3 (use for Retrofit 2.x)\n\nAdd using Gradle:\n```groovy\ncompile 'com.github.simonpercic:oklog3:2.3.0'\n```\n\nOR (for a pure-Java/Kotlin project, without dependencies on Android)\n\n```groovy\ncompile 'com.github.simonpercic:oklog3-java:2.3.0'\n```\n\nusage:\n\n```java\n// create an instance of OkLogInterceptor using a builder()\nOkLogInterceptor okLogInterceptor = OkLogInterceptor.builder().build();\n\n// create an instance of OkHttpClient builder\nOkHttpClient.Builder okHttpBuilder = new OkHttpClient.Builder();\n\n// add OkLogInterceptor to OkHttpClient's application interceptors\nokHttpBuilder.addInterceptor(okLogInterceptor);\n\n// build\nOkHttpClient okHttpClient = okHttpBuilder.build();\n```\n\n```java\n// use with Retrofit2\nnew Retrofit.Builder()\n    .baseUrl(baseUrl)\n    .client(okHttpClient)\n    ...\n    .build();\n```\n\n### Builder options\n- `setBaseUrl(String url)`\n    Set the base url to prefix the logs with. Useful if you're self-hosting [ResponseEcho](https://github.com/simonpercic/ResponseEcho). \n    Defaults to a hosted Heroku instance at: 'http://oklog.responseecho.com'\n   \n- `setLogInterceptor(LogInterceptor logInterceptor)` \n    Set a custom log interceptor to do your own logging. See [LogInterceptor](core/src/main/java/com/github/simonpercic/oklog/core/LogInterceptor.java) for details.\n    \n- `setLogger(Logger logger)` \n    Set a custom Logger to do your own logging. See [Logger](core/src/main/java/com/github/simonpercic/oklog/core/Logger.java) for details.\n    \n- `ignoreTimber(boolean ignoreTimber)`\n    Pass 'true' to ignore Timber for logging, even if it is present. \n    Since Timber is an optional dependency, OkLog will use it only if it's included it in your app's dependencies. If not, it will fallback to using Android's built-in Log methods.\n\n#### Additional log data options\n method                           | description                   | included by default\n----------------------------------|-------------------------------|------------------------------\nwithRequestBody(boolean)          |Include request body           |\u0026#10003; true\nwithRequestMethod(boolean)        |Include request method         |\u0026#10003; true\nwithRequestUrl(boolean)           |Include request url            |\u0026#10003; true\nwithProtocol(boolean)             |Include protocol               |\u0026#10007; false\nwithRequestContentType(boolean)   |Include request content type   |\u0026#10007; false\nwithRequestContentLength(boolean) |Include request content length |\u0026#10003; true\nwithRequestBodyState(boolean)     |Include request body state     |\u0026#10003; true\nwithRequestHeaders(boolean)       |Include request headers        |\u0026#10007; false\nwithRequestFailedState(boolean)   |Include request failed state   |\u0026#10003; true\nwithResponseCode(boolean)         |Include response code          |\u0026#10003; true\nwithResponseMessage(boolean)      |Include response message       |\u0026#10003; true\nwithResponseUrl(boolean)          |Include response url           |\u0026#10007; false\nwithResponseDuration(boolean)     |Include response duration      |\u0026#10003; true\nwithResponseSize(boolean)         |Include response size          |\u0026#10003; true\nwithResponseBodyState(boolean)    |Include response body state    |\u0026#10003; true\nwithResponseHeaders(boolean)      |Include response headers       |\u0026#10007; false\n\n- `withNoLogData() `\n    Don't include any additional log data from the options.\n    \n- `withAllLogData() `\n    Include all additional log data from the options.\n\n- `shortenInfoUrl(boolean) `\n    Shorten info url on the server-side, defaults to false.\n\n\n## Android and Java/Kotlin support\nThere are two variants of OkLog:\n- OkLog \u0026 OkLog3: for Android projects\n- OkLog-Java \u0026 OkLog3-Java: for pure Java/Kotlin projects (without Android dependencies)\n\n### The full variants matrix:\n\n x                          | Android         | pure Java/Kotlin (no-Android)\n----------------------------|-----------------|------------------------------\nOkHttp (Retrofit 1.x)       |oklog            |oklog-java\nOkHttp3 (Retrofit 2.x)      |oklog3           |oklog3-java\n\n\n## Known limitations\nOkLog for Android writes logs to Android's logging system, which has [a limited line length (~4000 chars)](http://stackoverflow.com/a/8899735). \n\nEven though the generated urls are gzipped and Base64 encoded, they **might still be longer than the log line limit** on very large http responses. \n\nUnfortunately, there is no workaround with the current system. Nevertheless, everything should work fine for the majority of cases.\n\nThis library optionally uses [Timber](https://github.com/JakeWharton/timber) for the actual logging, which splits lines that are too long, so you can see if a response was longer than the limit.\n\n\n## ProGuard\nProGuard configuration is already bundled with OkLog/3, so you can safely use it with ProGuard.\n\n\n## Privacy\nOkLog in combination with [ResponseEcho](https://github.com/simonpercic/ResponseEcho) are able to work by encoding request and response data in the URL path and query parameters.  \nConsequently, this data might be intercepted on the network.  \n\nThe hosted instance of ResponseEcho that OkLog points to by default is accessible over plain HTTP (not HTTPS).  \n\nIf you're concerned about your request and response data being intercepted, I strongly suggest you self-host ResponseEcho and set OkLog to point to your hosted instance (either locally or on your own server). \n\n### Url shortening\nWhen using the url-shortening option (either via an option in OkLog or by using the shorten button on the response info page), the response info is shortened using the [goo.gl](https://goo.gl) url shortener service via their REST API, see: [UrlShortenerManager.java](https://github.com/simonpercic/ResponseEcho/tree/master/src/main/java/com/github/simonpercic/responseecho/manager/urlshortener/UrlShortenerManager.java).\n\nSince the request and response data is included in the URL itself, shortening it using an external service consequently means that data is stored by the url shortening service provider.  \n\nIf you're concerned about your request and response data being stored by the shortening service, I strongly suggest you don't shorten the url.\n\n### Google Analytics\nGoogle Analytics is used in ResponseEcho to track its popularity and usage.  \nThere are two analytics methods included:\n- using the Google Analytics API, when showing the plain response data, see: [GoogleAnalyticsManager.java](https://github.com/simonpercic/ResponseEcho/tree/master/src/main/java/com/github/simonpercic/responseecho/manager/analytics/ga/GoogleAnalyticsManager.java).\n- using the Google Analytics Web tracking via JavaScript, when showing the response info, see: [base_head.html](https://github.com/simonpercic/ResponseEcho/tree/master/src/main/resources/templates/base_head.html).\n\nIn either of these methods, NO response data is included in the analytics tracking.\n\n\n## iOS\nIf you'd want to use OkLog in an iOS project, check out [OkLog-iOS](https://github.com/diegotl/OkLog-iOS), implemented by [Diego Trevisan](https://github.com/diegotl).  \n\n\n## Change Log\nSee [CHANGELOG.md](CHANGELOG.md)\n\n\n## License\nOpen source, distributed under the MIT License. See [LICENSE](LICENSE) for details.\n","funding_links":[],"categories":["开源库","日志库"],"sub_categories":["日志"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonpercic%2FOkLog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonpercic%2FOkLog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonpercic%2FOkLog/lists"}