Skip to content

Instantly share code, notes, and snippets.

@luisFebro
Last active February 23, 2025 18:52
Show Gist options
  • Save luisFebro/b247ba88fdf9cdb2a7e542debc690fd5 to your computer and use it in GitHub Desktop.
Save luisFebro/b247ba88fdf9cdb2a7e542debc690fd5 to your computer and use it in GitHub Desktop.
kotlin_dev_only_logger
/**
* Use this Logger utility to prevent app logs from leaking to production by default, following the Android security checklist and Google Play Guideline.
* Useful resources:
* https://youtu.be/Oqmoff2DmFw?t=61s
* https://developer.android.com/studio/publish/#publishing-prepare
* https://developer.android.com/privacy-and-security/security-tips#user-data
* https://www.netguru.com/blog/3-reasons-why-you-should-always-remove-logs-from-production-mobile-app
* adapted from Java: https://stackoverflow.com/a/46363450/10010404
*/
object Lo {
fun g(msg: String, tag: String? = null) {
if (BuildConfig.DEBUG) {
val isLogDLogger = tag?.isNotEmpty() == true
when {
isLogDLogger -> Log.d(tag, msg)
else -> println(msg)
}
}
}
}
/* USAGE EXAMPLE
Lo.g("TAG_hello_world") -> println("TAG_hello_world")
Lo.g("hello_world", tag = "FIRST_MSG")) -> Log.d("FIRST_MSG", "hello_world")
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment