eclipse 如何停止 logcat 消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18332657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to stop logcat messages
提问by Mick
I occasionally the following scenario when trying to debug my multi-threaded app. I run the program and then a bug occurs causing a useful message to appear in the log cat... but only for about a quarter of a second before scrolling off the top of the window because a seemingly never-ending stream of of not-so useful error messages floods into the window. I am then left desperately trying to grab the vertical scroll bar (which is now jiggling around) so as to position the original error message into the window before the window buffer becomes so full that it is discarded.
我在尝试调试我的多线程应用程序时偶尔会出现以下场景。我运行该程序,然后发生错误,导致在日志猫中出现有用的消息......但只持续了大约四分之一秒,然后从窗口顶部滚动,因为看似永无止境的非-如此有用的错误消息涌入窗口。然后我拼命地试图抓住垂直滚动条(现在正在摇晃),以便在窗口缓冲区变得如此满以致被丢弃之前将原始错误消息定位到窗口中。
There must be a better way... Is there a "stop-logging-now" command/button that I can hit as soon as the errors start appearing?
必须有更好的方法......是否有一个“立即停止记录”命令/按钮,我可以在错误开始出现时立即点击它?
回答by Mick
I've solved it. I just pull the USB cable out.
我已经解决了。我只是拔出USB电缆。
Not the most elegant solution... but it works.
不是最优雅的解决方案......但它有效。
回答by CRUSADER
Possible ways to solve the problem:-
解决问题的可能方法:-
- In Logcat, at top rightmost tab has a arrow pointing downward with line under it like you see in download button on websites . Just click it and your autoscrolling will stop .
- 在 Logcat 中,最右上方的选项卡有一个向下的箭头,下方有一条线,就像您在网站上的下载按钮中看到的那样。只需单击它,您的自动滚动就会停止。
- Just create a filter with the tag of the desired logs. Logcat will filter those messages out of the main logview and slow down the scrolling.
- 只需创建一个带有所需日志标签的过滤器。Logcat 会将这些消息从主日志视图中过滤出来并减慢滚动速度。
回答by WilliamK
The scroll lock of logcat still is annoying. Maybe they should copy the WireShirk scroll behavior:
logcat的scroll lock还是很烦人。也许他们应该复制 WireShirk 滚动行为:
when scrolling using middle mouse button, if it reaches the last line, autoscroll will activate. If scrolling up, deactivate autoscroll.
使用鼠标中键滚动时,如果到达最后一行,将激活自动滚动。如果向上滚动,请停用自动滚动。
回答by andy256
+1 for CRUSADER's answer.
+1 为 CRUSADER 的回答。
I have a different solution. I built a Logging
class, with the same interface as Log
, which logs to file andto logcat. I also add an UncaughtExceptionHandler
that uses my Logger
. Typical (cutdown) code in Logger
looks like
我有一个不同的解决方案。我构建了一个Logging
类,其接口与 相同Log
,它记录到文件和logcat。我还添加了一个UncaughtExceptionHandler
使用我的Logger
. 中的典型(缩减)代码Logger
看起来像
public void d(String tag, String message) {
Log.d(tag, message);
logLine('D', tag, message);
}
private void logLine(char category, String tag, String message) {
StringBuilder builder = new StringBuilder(tag.length()+message.length()+1);
builder.append(category).append(':').append(tag).append(':').append(message);
logStream.println(builder.toString());
logStream.flush();
logSize += builder.length()+1;
if (logSize > maxLogSize) {
String name = logName; // keep the old logName for continued message
close();
createLogFile(); // cleanup old logs and open a new one
logStream.println("Log continued from "+name);
}
}
A key reason for developing Logger
was to be able to send them in bug reports from beta testers. Because the interface is the same it can be used the same as the original Log
class.
开发的一个关键原因Logger
是能够将 Beta 测试人员的错误报告发送给他们。因为接口是一样的,所以可以像原来的Log
类一样使用。
回答by Sushil
You can pause logging by pressing
您可以通过按暂停记录
ctrl+S
and can resume logging by pressing:
并可以通过按恢复日志记录:
ctrl+Q
回答by Prahlad Yeri
The best way is filtering the logcat messages. While writing your error prone code, you can add a tag parameter to your logcat method. Then, in eclipse the logcat window lets you filter messages based on that tag, so you can see only those logs!
最好的方法是过滤 logcat 消息。在编写容易出错的代码时,您可以向 logcat 方法添加标签参数。然后,在 eclipse 中,logcat 窗口允许您根据该标签过滤消息,因此您只能看到那些日志!
回答by Nanne
You might want to go into debug mode, and stop execution alltogether at the point you're interested in?
您可能想要进入调试模式,并在您感兴趣的地方完全停止执行?
Put a break point in that piece of code, so you can not only check your error, but see the state of the various variables as well!
在那段代码中放置一个断点,这样您不仅可以检查错误,还可以查看各种变量的状态!