https://kotlinlang.org logo
#android
Title
# android
h

henrikhorbovyi

08/12/2019, 4:06 PM
Hey guys... Is it a bad practice to leave
logs
on the code (with the purpose of future debug)?
c

Casey Brooks

08/12/2019, 4:12 PM
To quote Jake Wharton: “…every time you log in production, a puppy dies” It’s generally OK to leave logging statements in your code as long as they are effectively a no-op when run in production. Libraries like Jake’s Timber provide a wrapper around the standard
Log
class to allow that kind of flexibility. The normal Android Logger still writes logs in production, and so you should avoid calling it directly if you intend to leave them in your code
h

henrikhorbovyi

08/12/2019, 4:14 PM
We use Timber.
Thanks for explain it 🙂
Recently I had the following problem. One guy from QA team came to me showing the app in staging with one empty screen (apparently a bug). I get the phone and plug on my laptop, but no logs appeared. My solution: I put the log to show data coming from api and run on his phone again to apply the changes, but I lose the session because the app was reinstalled and loose the cache. When he logged in again the error didn't appear anymore ahahaha;
k

Kris Wong

08/12/2019, 4:22 PM
logging is immensely helpful in troubleshooting. as far as where and when you log, there are lots of options
we use a ring buffer style log persisted to a memory mapped file in our app sandbox, as an example
h

henrikhorbovyi

08/12/2019, 4:23 PM
The situation that I told happened because in our team people tend to clean the logs before send to codereview
k

Kris Wong

08/12/2019, 4:24 PM
we tend to reject a PR if it doesn't have sufficient logging 🙂
h

henrikhorbovyi

08/12/2019, 4:25 PM
Cool...
Because here in our project we don't have this >>>>>
Untitled
as @Simon pointed
To don't don't allow prod logs
k

Kris Wong

08/12/2019, 4:26 PM
i would not recommend that myself, but to each their own
h

henrikhorbovyi

08/12/2019, 4:27 PM
And then the devs think that after testing we should remove our logs
Got it
c

Casey Brooks

08/12/2019, 4:29 PM
The main reason you’d want to turn off logging in production is so that potentially-sensitive information is never made visible to the end-user. Logcat is a global thing in Android with no protection around it, so other apps might be able to scrape API keys, PII, etc. from logs. I tend to check in lot of logging so that my QA team can identify problems and so I don’t have keep adding/removing them on my end while debugging. But logging is enabled in debug and QA builds only. Once a feature has been stable in production for a while, I tend to go back and remove its logs to keep everything clean
k

Kris Wong

08/12/2019, 4:31 PM
definitely keep PII out of logging
h

henrikhorbovyi

08/12/2019, 4:32 PM
Yeah.. sure
j

Jeremy

08/12/2019, 9:24 PM
Depending on nature of app you can also set logging levels and on/off via config flags remotely
h

henrikhorbovyi

08/13/2019, 1:35 AM
ah! Good idea.
k

Kris Wong

08/13/2019, 12:54 PM
or with a user preference