0

Recently, I read the codes of android native app OneTimeInitializer. There are such codes make me confused.

public class OneTimeInitializerService extends IntentService {

    // class name is too long
    private static final String TAG = OneTimeInitializerService.class.getSimpleName()
        .substring(0, 22);
    //...
}

Why it says "class name is too long" and calls "substring(0, 22)"? Does the tag of logcat should not be too long?

Chris Emerson
  • 13,041
  • 3
  • 44
  • 66
czjabc
  • 1
  • 1

1 Answers1

2

Log tag's length must be < 23

you can check documentation detail provided under isLoggable

IllegalArgumentException is thrown if the tag.length() > 23.

Here are some links you need to follow link1, link2

Don't forget to check official document of Log

Community
  • 1
  • 1
Ravi
  • 34,851
  • 21
  • 122
  • 183
  • 1
    Thanks for your answer and advice. – czjabc Nov 09 '16 at 12:57
  • 1
    According to the docs, this only applies for API <= 23: "for Nougat (7.0) releases (API <= 23) and prior, there is no tag limit of concern after this API level" – Traendy Jan 25 '21 at 15:12
  • @Traendy This is tragic. I now need to change all of log.x() statements that I wrote in the API 8 days. – WebViewer Jan 12 '23 at 14:34