Date post: | 14-Apr-2017 |
Category: |
Mobile |
Upload: | simon-percic |
View: | 73 times |
Download: | 0 times |
Effortless network response logging on Android
Simon Perčič, senior Android developer
Thursday, April 21st, 2016 @ 17:00
http://square.github.io/okhttp/
Networking on Android
http://square.github.io/retrofit/
Retrofit 1
Retrofit 2
Retrofit 2
Logging: Retrofit → OkHttp’s interceptors
Retrofit 2
How does the log output look like?
JSON formatter / JSON viewer
OkLog
https://github.com/simonpercic/OkLog
OkLog
OkLog
Share url with coworkers.
(Usually REST API developers)
“OkLog is like git blame, but for network requests”
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
Ok, how do I use it?
1.
2.
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
Non-logging approaches
Facebook’s Stetho
http://facebook.github.io/stetho/
Non-logging approaches
Charles Proxy
https://www.charlesproxy.com
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
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
Questions?
@simonpercic @simonpercicsimonpercic