Hey guys... Is it a bad practice to leave `logs` o...
# android
h
Hey guys... Is it a bad practice to leave
logs
on the code (with the purpose of future debug)?
c
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
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
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
The situation that I told happened because in our team people tend to clean the logs before send to codereview
k
we tend to reject a PR if it doesn't have sufficient logging 🙂
h
Cool...
Because here in our project we don't have this >>>>>
Untitled
as @Simon pointed
To don't don't allow prod logs
k
i would not recommend that myself, but to each their own
h
And then the devs think that after testing we should remove our logs
Got it
c
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
definitely keep PII out of logging
h
Yeah.. sure
j
Depending on nature of app you can also set logging levels and on/off via config flags remotely
h
ah! Good idea.
k
or with a user preference