Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Effortless network response logging on Android

Effortless network response logging on Android

While developing an Android app that gets data from a remote server, you often need to see what data you’re actually receiving. I explain what options you have to inspect network responses when using Retrofit and OkHttp, two of the most popular networking libraries for Android.

Simon Perčič

April 21, 2016
Tweet

More Decks by Simon Perčič

Other Decks in Programming

Transcript

  1. OkLog Share url with coworkers. (Usually REST API developers) “OkLog

    is like git blame, but for network requests”
  2. How does it work? Response string from OkHttp via application-level

    interceptor gzip Base64 encode Create url and write string to log (w/ Timber if present) OkLog Get string from url param Base64 decode un-gzip Return string to browser, pretty-print if JSON ResponseEcho
  3. Known limitations - Android’s logging system: limited line length ~4k

    chars - on some very long responses, 4k chars is not enough, even if gzipped - if using Timber, url is split into multiple lines ...everything works fine for the majority of cases
  4. Which one should you use? - No silver bullet that

    would cover all cases - Use side-by-side, depending on the use case you want to cover
  5. Logging in production “every time you log in production, a

    puppy dies.” - Jake Wharton, Timber readme (https://github.com/JakeWharton/timber) http://developer.android.com/tools/publishing/preparing.html#publishing-configure