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

Do *not* truncate tags over 23 characters #350

Closed
consp1racy opened this issue Feb 18, 2019 · 8 comments
Closed

Do *not* truncate tags over 23 characters #350

consp1racy opened this issue Feb 18, 2019 · 8 comments

Comments

@consp1racy
Copy link

Quoting my comment #196 (comment)

Log doesn't care at all how long the tags are.

The only thing where is an issue is that Log.isLoggable checks a system property. And system property keys were until API 24 limited in length to 31 characters. And "log.tag.".size + 23 equals 31.

Source:

Going forward LogcatTree could

  • drop this limitation entirely or
  • enforce it for one or both of checking and printing just when withCompliantLogging() is used.
@consp1racy
Copy link
Author

I just combed through AOSP API 25 and the check is still in place. The documentation for Log.isLoggable got updated in Oreo with the wrong thing. Looks like we should be checking tag length until API 26.

Folow https://issuetracker.google.com/issues/124593220

@JakeWharton
Copy link
Owner

This behavior already exists:

// Tag length limit was removed in API 24.
if (tag.length() <= MAX_TAG_LENGTH || Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return tag;
}

@consp1racy
Copy link
Author

consp1racy commented Feb 18, 2019

You missed the point. isLoggable isn't safe. Actual logging is.

And the second point, it isn't safe up until and including API 25. The documentation is wrong.

@JakeWharton
Copy link
Owner

We don't call that API.

@consp1racy
Copy link
Author

Ok, in which case we don't have to truncate the tags at all. The only thing that throws is Log.isLoggable below API 26. Again, the actual logging doesn't care about tag length (according to AOSP).

Plus the new LogcatTree.withCompliantLogging() does call Log.isLoggable.

I probably should draft a sample project.

@JakeWharton
Copy link
Owner

JakeWharton commented Feb 18, 2019 via email

@consp1racy
Copy link
Author

consp1racy commented Feb 18, 2019

Admittedly, C is not my forte... Anyway, how is it then possible that logging with tags over 23 characters just works everywhere I tried?

I took a Huawei ALE-L21 with Android 6, whipped out a Samsung Galaxy SII running Android 4.1, and unearthed a HTC Vision with a dusty Gingerbread. All of them log just fine, until I call Log.isLoggable.

And on the other side we have my old Xperia L with an unofficial Android 7.1 that throws IllegalArgumentException while according to the documentation logn tags should be allowed.

Here's the sample project: https://github.com/consp1racy/android-test-loggable

Here's a sample input:

Log.w("The wheels on the bus go round and round, round and round, round and round", "Hello, World!")

Here's a sample output:

01-06 01:11:29.321 2343-2343/net.xpece.test.loggable W/The wheels on the bus go round and round, round and round, round and round: Hello, World!

Bottom line:

  • Log.isLoggable documentation is wrong. It checks tag length until and including API 25. This is important for the new LogcatTree.withCompliantLogging.
  • Log.w logs long tags just fine on everything I tested. This is important for the whole Timber.

Another logging library has observed the same thing: https://jira.qos.ch/browse/SLF4J-164

I wouldn't even know that too long tags was a thing until one day Timber just started truncating them out of the blue. Everything worked fine.

The struct sent to the kernel only had 23 bytes until API 24

Why does it still work? It prints the tag from unallocated memory until it encounters a \0? What's happening there? 23 bytes isn't even 23 wide characters.

@JakeWharton
Copy link
Owner

I don't see a reason to bother with changing this. The limitation is removed on new API levels and the restriction was widely understood to exist prior to that. Whether it actually is enforced and where is an implementation detail and I don't want to mess with it.

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

No branches or pull requests

2 participants