Skip to content

Commit 6bedb26

Browse files
committed
Handle log tag namespacing in formatTag
1 parent 4d3f0ba commit 6bedb26

File tree

1 file changed

+18
-11
lines changed
  • app/src/main/java/tech/httptoolkit/android

1 file changed

+18
-11
lines changed

app/src/main/java/tech/httptoolkit/android/Tag.kt

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,28 @@ import android.os.Build
44

55
fun formatTag(tag: String): String {
66
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
7-
tag
7+
if (tag.startsWith("tech.httptoolkit.android")) {
8+
tag
9+
} else {
10+
// In some cases (e.g. coroutines) our code runs in the context of
11+
// other classes - make sure we prefix it for findability regardless.
12+
"tech.httptoolkit.android ($tag)"
13+
}
814
} else {
9-
tag.substring(0, 23) // Before API 24 there's a 23 char length limit
15+
// Before API 24 there's a 23 char length limit we need to stay under:
16+
(
17+
if (tag.startsWith("tech.httptoolkit.android")) {
18+
tag.replace("tech.httptoolkit.android", "tech.httptoolkit...")
19+
} else {
20+
// In some cases (e.g. coroutines) our code runs in the context of
21+
// other classes - make sure we prefix it for findability regardless.
22+
"tech.httptoolkit... ($tag)"
23+
}
24+
).substring(0, 23)
1025
}
1126
}
1227

1328
val Any.TAG: String
1429
get() {
15-
val name = if (javaClass.name.startsWith("tech.httptoolkit.android")) {
16-
javaClass.name
17-
} else {
18-
// In some cases (e.g. coroutines) our code runs in the context of
19-
// other classes - make sure we prefix it for findability regardless.
20-
"tech.httptoolkit.android ($javaClass.name)"
21-
}
22-
23-
return formatTag(name)
30+
return formatTag(javaClass.name)
2431
}

0 commit comments

Comments
 (0)