@@ -3,25 +3,29 @@ package info.hannes.timber
33import org.json.JSONException
44import org.json.JSONObject
55import timber.log.Timber
6+ import timber.log.Timber.Forest.tag
67
78/* If you use old logcat, e.g Android Studio Electric Eel, you should use for newLogcat a false */
89open class DebugFormatTree (private val newLogcat : Boolean = true ) : Timber.DebugTree() {
910
1011 private var codeIdentifier = " "
12+ private var method = " "
1113
1214 override fun createStackElementTag (element : StackTraceElement ): String? {
1315 if (newLogcat) {
14- codeIdentifier = String .format(
15- " (%s:%d)" ,
16- element.fileName,
17- element.lineNumber // format ensures line numbers have at least 3 places to align consecutive output from the same file
18- )
19- return String .format(
16+ method = String .format(
2017 " %s.%s()" ,
2118 // method is fully qualified only when class differs on filename otherwise it can be cropped on long lambda expressions
2219 super .createStackElementTag(element)?.replaceFirst(element.fileName.takeWhile { it != ' .' }, " " ),
2320 element.methodName
2421 )
22+
23+ codeIdentifier = String .format(
24+ " (%s:%d)" ,
25+ element.fileName,
26+ element.lineNumber // format ensures line numbers have at least 3 places to align consecutive output from the same file
27+ )
28+ return " (${element.fileName} :${element.lineNumber} )"
2529 } else
2630 return String .format(
2731 " (%s:%d) %s.%s()" ,
@@ -45,6 +49,6 @@ open class DebugFormatTree(private val newLogcat: Boolean = true) : Timber.Debug
4549 }
4650 if (newLogcat)
4751 localMessage = codeIdentifier + localMessage
48- super .log(priority, tag, localMessage, t)
52+ super .log(priority, tag, " $method : $ localMessage" , t)
4953 }
5054}
0 commit comments