为什么 logcat 会忽略带有“PHONE”标签的日志语句?
我在呼叫按钮上设置了一个侦听器,起初我只是想确保侦听器正在工作,所以我在其中添加了一条日志语句。但由于某种神秘的原因,当我点击它时它拒绝打印!所以我想,也许呼叫按钮为空,并添加了一条 else 语句...但它没有从 if 或 else 语句中打印任何内容!它会打印之前和之后的语句,但完全忽略 if-else 结构中的所有内容。代码如下:
ImageButton call = (ImageButton) v.findViewById(R.id.callButton);
Log.d("MEETINGS", "ABOUT TO WORK W/ CALL");
Log.e("MEETINGS", "" + (call != null));
if (call != null) {
Log.d("PHONE", "setting stuff on call...");
call.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Log.d("PHONE", "on call : " + phone);
}
});
} else {
System.out.println("why is this messed up");
Log.d("PHONE", "call button was null!");
}
System.out.println("what the heck is going on");
在尝试解开 Java 如何决定跳过 if 和 else 的谜团至少 15 分钟之后,我尝试为日志语句赋予不同的标签。
尤里卡!这就成功了!我把“PHONE”改为“BLAH”,突然间世界又变得有意义了!出于好奇,我将其更改为“电话”,但它拒绝再次打印。
这个故事的寓意是:永远不要在 logcat 中使用“phone”或“PHONE”标签!
有人可以向我解释一下 logcat 如何和/或为什么忽略带有“PHONE”标签的消息吗?
I was setting a listener on my call button and at first I just wanted to make sure that the listener was working, so I put a log statement inside of it. But for some mysterious reason, it refused to print when I clicked it! So maybe the call button was null, I thought, and added an else statement...but it didn't print anything from either the if or the else statement!!! It would print the statements before and after, but totally ignore everything in the if-else structure. Here's the code:
ImageButton call = (ImageButton) v.findViewById(R.id.callButton);
Log.d("MEETINGS", "ABOUT TO WORK W/ CALL");
Log.e("MEETINGS", "" + (call != null));
if (call != null) {
Log.d("PHONE", "setting stuff on call...");
call.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Log.d("PHONE", "on call : " + phone);
}
});
} else {
System.out.println("why is this messed up");
Log.d("PHONE", "call button was null!");
}
System.out.println("what the heck is going on");
After at least 15 minutes of trying to unravel the mystery of how Java could just decide to skip both the if and the else, I tried giving the log statement a different tag.
And eureka! That did the trick! I changed "PHONE" to "BLAH" and suddenly the world made sense again! Curious, I changed it to "phone" and it refuses to print again.
Moral of the story: never use the tag "phone" or "PHONE" in logcat!!!
Can someone please explain to me how and/or why logcat ignores messages with the tag "PHONE"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅 isLoggable( )。我猜测您的手机上已禁用“PHONE”标签的调试输出,以抑制实际手机应用程序的输出。
我相信您应该能够在手机上的 shell 中运行“getprop log.tag.PHONE”,以检索打印标记为“PHONE”的消息所需的最低严重级别。
See the documentation for isLoggable(). I'm guessing debug output for the "PHONE" tag has been disabled on your phone to suppress output from the actual phone application.
I believe you should be able to run "getprop log.tag.PHONE" in a shell on the phone to retrieve the minimum severity level required for messages tagged "PHONE" to be printed.