The logging tag can be at most 23 characters

后端 未结 8 1518
-上瘾入骨i
-上瘾入骨i 2020-12-13 12:46

Since update AS 1.1 Preview 2, I\'m getting red lines under all my Log messages

Log.d(TAG, \"message\");

With message: \"

相关标签:
8条回答
  • 2020-12-13 13:00

    You can disable it if you so choose.

    In Android Studio, Analyze->Inspect Code.

    screenshot

    Under Inspection Profile, click on the button with the 3 horizontal dots.

    The following window should open. Search for "log" and uncheck "Too Long Log Tags".

    screenshot

    Update: Android Studio 2.2, it is located under Android Lint: Correctness

    screenshot

    0 讨论(0)
  • 2020-12-13 13:09

    This error was thrown for me for a node_module library, complaining about a separate node_mode library.

    I added this lint options property within that node_module library's build gradle file.

      android {
          lintOptions {
              abortOnError false
          }
      }
    

    The library was aws-amplify push notification.

    Error: Execution failed for task ':@aws-amplify/pushnotification:lint'

    File updated: node_modules/@aws-amplify/pushnotification/android/build.gradle

    0 讨论(0)
  • 2020-12-13 13:14

    No, it's not a bug.

    From Android Studio's Recent Changes on 1.1 Preview 2,

    Checks that the tag passed to the logging calls, if its value can be resolved, is at most 23 characters long (as required by the Logging API.)

    logging tag was 31

    As shortly explained on the recent changes, it's due to how Log API doesn't allow tag that exceeds 23 characters.

    SLF4J Android has an explanation to this:

    [...] the length of such tags is currently limited to 23 characters (23 = 32 - 8 for namespace prefix - 1 for C terminator)

    which matches the Android's source code.

    Currently, the only function that explicitly mentions this exception is Log.isLoggable(),

    ...

    Throws

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

    However, based on the comments, apparently the logger does throw the exception on release mode (it's ignored in debug mode).

    You can disable the lint checking by following Terence's answer, but you've been warned.

    0 讨论(0)
  • 2020-12-13 13:17

    This is recent change and In this build, its a new lint check. Which says,

    Checks that the tag passed to the logging calls, if its value can be resolved, is at most 23 characters long (as required by the Logging API.)

    For more info, read 3rd point in below link.

    https://sites.google.com/a/android.com/tools/recent/androidstudio11preview2

    If you dont want to get this, minimize the number of characters in your TAG and make sure that they wont cross the length more than 23.

    0 讨论(0)
  • 2020-12-13 13:17

    Solution. Year 2020 ver.

    build.gradle (app)

    android {
        lintOptions {
            disable 'LongLogTag'
        } // put this. 
    }
    
    0 讨论(0)
  • 2020-12-13 13:26

    Complementing the answer by @Terence

    You can also turn off the specific check via gradle with this in your build.gradle file:

    lintOptions {
        disable 'LongLogTag'
    }
    

    Or by adding a lint.xml file to your project with xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <lint>
        <issue id="LongLogTag" severity="ignore" />
    </lint>
    
    0 讨论(0)
提交回复
热议问题