Skip to content

Commit a8b2efc

Browse files
authored
Merge pull request #526 from AppDevNext/AdaptLogFormat
Adapt log format
2 parents 8656fac + 0cfc593 commit a8b2efc

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

LogcatCoreLib/src/main/java/info/hannes/timber/DebugFormatTree.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,29 @@ package info.hannes.timber
33
import org.json.JSONException
44
import org.json.JSONObject
55
import 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 */
89
open 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

Comments
 (0)