Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@alexstyl
Created February 12, 2022 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexstyl/15c1ebe8877faf2847f32e09b2513afa to your computer and use it in GitHub Desktop.
Save alexstyl/15c1ebe8877faf2847f32e09b2513afa to your computer and use it in GitHub Desktop.
import android.util.Log
object Logs {
var isLoggingEnabled = false
private const val TAG = "Logs"
private const val PREFIX = ">>>PREFIX:"
fun verboseln(message: () -> String) {
if (isLoggingEnabled) {
Log.v(TAG, "$PREFIX ${message.invoke()}")
}
}
fun debugln(message: () -> String) {
if (isLoggingEnabled) {
Log.d(TAG, "$PREFIX ${message.invoke()}")
}
}
fun infoln(message: () -> String) {
if (isLoggingEnabled) {
Log.i(TAG, "$PREFIX ${message.invoke()}")
}
}
fun warningln(message: () -> String) {
if (isLoggingEnabled) {
Log.w(TAG, "$PREFIX ${message.invoke()}")
}
}
fun warningln(error: Throwable) {
if (isLoggingEnabled) {
error.printStackTrace()
}
}
fun errorln(message: () -> String) {
if (isLoggingEnabled) {
Log.e(TAG, "$PREFIX ${message.invoke()}")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment