7
votes

Numéro de ligne dans Android Log Util

Y a-t-il un moyen d'imprimer le numéro de ligne de fichier avec Android Log ?

Entrez la description de l'image ici


2 commentaires

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/...


4 Réponses :


10
votes

pour obtenir le numéro de ligne ` xxx

` essayez ça va vous aider ....


0 commentaires

0
votes

Pour accomplir cela, voici ce que j'ai fait (le numéro de ligne de sortie% L): xxx


0 commentaires

2
votes

Meilleure journalisation dans Android à l'aide du bois avec le numéro de la ligne de journalisation

in /app/build.gradle fichier xxx

dans la classe d'application xxx


0 commentaires

0
votes
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()
  }
}

0 commentaires