-
Notifications
You must be signed in to change notification settings - Fork 967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timber.debugTree splite lose word #339
Comments
and, android studio 3.2 default line size less then 4000 |
4023 is the max (prior to 24 or whatever) which is why it's set at 4000.
You can file an Android Studio bug if it cannot properly display more than
3000.
…On Mon, Oct 22, 2018 at 10:19 PM Victor ***@***.***> wrote:
and, android studio 3.2 default line size less then 4000
MAX_LOG_LENGTH should be set 3000 or other
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#339 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEEEVmF3pq-otHQalpeon57tp0I5Bspks5unnzFgaJpZM4Xy4ki>
.
|
Now the latest version of Android Studio is 4.1.1。It still can't properly display more than 3000. I hope the MAX_LOG_LENGTH should change to 3000 or make it can change. Now in my project, I extend the DebugTree, only change the MAX_LOG_LENGTH, and copy and paste the fun of |
Sounds like a Studio bug then. File it on their project? |
class MyDebugTree : Timber.DebugTree() {
private val MAX_LOG_LENGTH = 2048
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
if (message.length < MAX_LOG_LENGTH) {
if (priority == Log.ASSERT) {
Log.wtf(tag, message)
} else {
Log.println(priority, tag, message)
}
return
}
// Split by line, then ensure each line can fit into Log's maximum length.
var i = 0
val length = message.length
while (i < length) {
var newline = message.indexOf('\n', i)
newline = if (newline != -1) newline else length
do {
val end = Math.min(newline, i + MAX_LOG_LENGTH)
val part = message.substring(i, end)
if (priority == Log.ASSERT) {
Log.wtf(tag, part)
} else {
Log.println(priority, tag, part)
}
i = end
} while (i < newline)
i = if (i == newline) i + 1 else i
}
}
} 我做了一些改动,这样就没问题了 |
I think I know the reason. It should be the Chinese character problem. The three byte Chinese makes the calculation error |
You're saying the kernel header is in utf-8(?) bytes but Timber is erroneously counting chars? That sounds like a plausible explanation! |
The same happens for Cyrillic text, approximately half of it is lost. :( |
Yes, kernel is counting text size in utf-8, so... import android.icu.text.BreakIterator
import android.icu.util.ULocale
import timber.log.Timber
class CountingDebugTree(private val locale: ULocale = ULocale.getDefault()) : Timber.DebugTree() {
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
if (message.length <= PESSIMISTIC_MAX_LOG_LENGTH) {
return super.log(priority, tag, message, t)
}
val iterator = BreakIterator.getCharacterInstance(locale)
iterator.setText(message)
var count = 0
var begin = iterator.first()
var end = begin
while (end < message.length) {
if (message[end] == '\n') {
super.log(priority, tag, message.substring(begin, end), t)
count = 0
begin = iterator.next()
end = iterator.next()
continue
}
val next = iterator.next()
val bytes = message.utf8Length(end, next)
if (count + bytes > MAX_LOG_BYTES) {
super.log(priority, tag, message.substring(begin, end), t)
count = 0
begin = end
}
count += bytes
end = next
}
if (count > 0) {
super.log(priority, tag, message.substring(begin), t)
}
}
private fun String.utf8Length(from: Int, to: Int): Int {
var i = from
var count = 0
while (i < to) {
val bytes = when {
this[i] <= '\u007F' -> 1
this[i] <= '\u07FF' -> 2
this[i].isHighSurrogate() -> 4
else -> 3
}
count += bytes
i += if (bytes == 4) 2 else 1
}
return count
}
companion object {
private const val MAX_LOG_BYTES = 4000
private const val PESSIMISTIC_MAX_LOG_LENGTH = MAX_LOG_BYTES / 3
}
} |
The text was updated successfully, but these errors were encountered: