Skip to content
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

Open
imcloud opened this issue Oct 22, 2018 · 8 comments
Open

Timber.debugTree splite lose word #339

imcloud opened this issue Oct 22, 2018 · 8 comments
Labels

Comments

@imcloud
Copy link

imcloud commented Oct 22, 2018

// Split by line, then ensure each line can fit into Log's maximum length.
      for (int i = 0, length = message.length(); i < length; i++) {
        int newline = message.indexOf('\n', i);
        newline = newline != -1 ? newline : length;
        do {
          int end = Math.min(newline, i + MAX_LOG_LENGTH);
          String part = message.substring(i, end);
          if (priority == Log.ASSERT) {
            Log.wtf(tag, part);
          } else {
            Log.println(priority, tag, part);
          }
          i = end;
        } while (i < newline);
      }
// the beginning index, inclusive.
// the ending index, exclusive
// while i == 0
message.substring(0, 4000);
// while i == 1
message.substring(4001, 8001);

// lost 4000
@imcloud
Copy link
Author

imcloud commented Oct 23, 2018

and, android studio 3.2 default line size less then 4000
MAX_LOG_LENGTH should be set 3000 or other

@JakeWharton
Copy link
Owner

JakeWharton commented Oct 23, 2018 via email

@taichushouwang
Copy link

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 log

@JakeWharton
Copy link
Owner

Sounds like a Studio bug then. File it on their project?

@imcloud
Copy link
Author

imcloud commented Dec 25, 2020

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 log

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
        }
    }
}

我做了一些改动,这样就没问题了

@imcloud
Copy link
Author

imcloud commented Mar 10, 2021

I think I know the reason. It should be the Chinese character problem. The three byte Chinese makes the calculation error

@JakeWharton
Copy link
Owner

You're saying the kernel header is in utf-8(?) bytes but Timber is erroneously counting chars? That sounds like a plausible explanation!

@gmk57
Copy link

gmk57 commented Jun 1, 2021

The same happens for Cyrillic text, approximately half of it is lost. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants