Y a-t-il un moyen d'imprimer le numéro de ligne de fichier avec Android Log ? p>
p>
4 Réponses :
pour obtenir le numéro de ligne ` `
essayez ça va vous aider .... p> p>
Pour accomplir cela, voici ce que j'ai fait (le numéro de ligne de sortie% L):
in
object Logg { private fun tag(): String? { return Thread.currentThread().stackTrace[4].let { val link = "(${it.fileName}:${it.lineNumber})" val path = "App# ${it.className.substringAfterLast(".")}.${it.methodName}" if (path.length + link.length > 80) { "${path.take(80 - link.length)}...${link}" } else { "$path$link" } } } fun v(msg: String?) { Log.v(tag(), "ð $msg") } fun d(msg: String?) { Log.d(tag(), "ð $msg") } fun i(msg: String?) { Log.i(tag(), "ð $msg") } fun w(msg: String?) { Log.w(tag(), "ð $msg") } fun w(e: Throwable?) { Log.w(tag(), "ð ${e?.localizedMessage}") e?.printStackTrace() } fun w(e: Exception?) { Log.w(tag(), "ð ${e?.localizedMessage}") e?.printStackTrace() } fun w(e: LinkageError?) { Log.w(tag(), "ð ${e?.localizedMessage}") e?.printStackTrace() } fun e(msg: String?) { Log.e(tag(), "ð $msg") } fun e(e: Throwable?) { Log.e(tag(), "ð ${e?.localizedMessage}") e?.printStackTrace() } fun e(e: java.lang.Exception?) { Log.e(tag(), "ð ${e?.localizedMessage}") e?.printStackTrace() } }
Reportez-vous à la discussion sur ce thread: Stackoverflow.com/Questtions/115008/...
Vérifiez ce fil et cette réponse de Michael Baltaks, cela pourrait vous aider. Stackoverflow.com/Questtions/115008/...