日志标签最多可以有 23 个字符 [英] The logging tag can be at most 23 characters

查看:27
本文介绍了日志标签最多可以有 23 个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从更新 AS 1.1 Preview 2 以来,我的所有 Log 消息下都有红线

Log.d(TAG, "message");

带有消息:日志标签最多可以包含 23 个字符..".

我没有从根本上更新任何东西,除了 Android Studio 本身.这是一个错误吗?

解决方案

不,这不是错误.

来自 API 不允许超过 23 个字符的标签.

SLF4J Android 对此有一个解释:

<块引用>

[...] 此类标签的长度目前限制为 23 个字符(名称空间前缀为 23 = 32 - 8 - C 终止符为 1)

Android的源代码相匹配

一>.

目前,唯一明确提及此异常的函数是 Log.isLoggable(),

<块引用>

...

投掷

IllegalArgumentException 如果 tag.length() >23.

但是,根据评论,显然记录器确实在发布模式下抛出异常(在调试模式下被忽略).

您可以按照 Terence 的回答禁用 lint 检查,但您已收到警告.

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

Log.d(TAG, "message");

With message: "The logging tag can be at most 23 characters..".

I didn't update anything fundamentally, except Android Studio itself. Is this a bug?

解决方案

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.)

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.

这篇关于日志标签最多可以有 23 个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆