Created
October 24, 2017 04:18
-
-
Save Kraiden/52d77aefe2bde00a978cb2c6428d7723 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.util.Log | |
class ELog() { | |
companion object { | |
@JvmStatic fun d(tag: String, msg: String) = Log.d(tag, prependFile(msg)) | |
@JvmStatic fun d(tag: String, msg: String, tr: Throwable) = Log.d(tag, prependFile(msg),tr) | |
@JvmStatic fun i(tag: String, msg: String) = Log.i(tag, prependFile(msg)) | |
@JvmStatic fun i(tag: String, msg: String, tr:Throwable) = Log.i(tag, prependFile(msg),tr) | |
@JvmStatic fun v(tag: String, msg: String) = Log.v(tag, prependFile(msg)) | |
@JvmStatic fun v(tag: String, msg: String, tr:Throwable) = Log.v(tag, prependFile(msg),tr) | |
@JvmStatic fun e(tag: String, msg: String) = Log.e(tag, prependFile(msg)) | |
@JvmStatic fun e(tag: String, msg: String, tr:Throwable) = Log.e(tag, prependFile(msg),tr) | |
@JvmStatic fun w(tag: String, msg: String) = Log.w(tag, prependFile(msg)) | |
@JvmStatic fun w(tag: String, msg: String, tr:Throwable) = Log.w(tag, prependFile(msg),tr) | |
@JvmStatic fun wtf(tag: String, msg: String) = Log.wtf(tag, prependFile(msg)) | |
@JvmStatic fun wtf(tag: String, msg: String, tr:Throwable) = Log.wtf(tag, prependFile(msg),tr) | |
private inline fun prependFile(str: String): String { | |
val frame = Exception().stackTrace[1] | |
return ".(${frame.fileName}:${frame.lineNumber}) - $str" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using this will prepend the filename and line number to your log message, making them clickable in Android Studio