Eclipse 中的 LogCat 是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7188115/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 16:54:11  来源:igfitidea点击:

What is LogCat in Eclipse?

javaandroideclipse

提问by Karate_Dog

What does LogCat do in Eclipse?

LogCat 在 Eclipse 中做什么?

How do I use it? I have never used the log cat before in Eclipse, so I don't understand.

我该如何使用它?之前在Eclipse里没用过log cat,所以不明白。

采纳答案by Pratik

This is a nice and quick way to exchange information from the application on your device and the development computer.

这是从设备和开发计算机上的应用程序交换信息的好方法。

To use Logcat, first import android.util.Loginto your project. Now you can call the static class Log from your project to start logging. As you can see below, Logcat has different levels of logging. When debugging, we'll just use Debug (D) to log the progress. Of course, when you want to log an actual error, you will use Error (E).

要使用 Logcat,首先要导入android.util.Log到您的项目中。现在您可以从您的项目中调用静态类 Log 来开始记录。如下所示,Logcat 具有不同级别的日志记录。调试时,我们将只使用 Debug (D) 来记录进度。当然,当您想记录实际错误时,您将使用错误 (E)。

V — Verbose (lowest priority)
D — Debug
I — Info
W — Warning
E — Error
F — Fatal
S — Silent (highest priority, on which nothing is ever printed)

For more detail, see Debugging in Android using Eclipse.

有关更多详细信息,请参阅使用 Eclipse 在 Android 中调试

回答by Shlublu

LogCat is an Android feature that allows you viewing logs emitted by the applications running on an Android device.

LogCat 是一项 Android 功能,可让您查看由在 Android 设备上运行的应用程序发出的日志。

When you are running your application in debugging mode from Eclipse, you can see plenty of logs appearing in this window: those of your own application, but also those posted by the system and other applications running at the same time on this device.

当您在 Eclipse 中以调试模式运行您的应用程序时,您可以看到此窗口中出现大量日志:您自己的应用程序的日志,以及系统和同时在此设备上运行的其他应用程序发布的日志。

To log something, you have first to determine how your message is critical (is this debuggin info, an informational message, a warning or an actual error message?) and then use the appropriate method:

要记录某些内容,您必须首先确定您的消息有多重要(这是调试信息、信息性消息、警告还是实际错误消息?)然后使用适当的方法:

Log.d("myApp", "my debug message");  
Log.i("myApp", "my informational message");
Log.w("myApp", "my warning message");
Log.e("myApp", "my error message");

回答by Niranj Patel

Debugging in Android using Eclipsehere is good explantation of how to debug your applications using the Eclipse IDE with the Android plugins,

此处使用 Eclipse 在 Android 中调试很好地解释了如何使用带有 Android 插件的 Eclipse IDE 调试您的应用程序,

回答by Joje

You use LogCat by adding commands like this in your code:

您可以通过在代码中添加这样的命令来使用 LogCat:

Log.d(TAG, stringVar);

Log.d(TAG, stringVar);

The TAG is a string constant that will help filter the output from LogCat. The TAG may be the name of your Activity or Application. You use the filter in the LogCat window to see only the filtered output.

TAG 是一个字符串常量,有助于过滤 LogCat 的输出。TAG 可能是您的活动或应用程序的名称。您可以使用 LogCat 窗口中的过滤器来仅查看过滤后的输出。

String TAG = "AppName";

String TAG = "应用名称";

The stringVar can contain anything that may be helpful for your understanding of how the code works when you need to debug it,

stringVar 可以包含任何可能有助于您在需要调试时理解代码工作方式的内容,

An example is if you are unsure of the value of an int variable (f.ex. intVal): --- code --

例如,如果您不确定 int 变量的值(例如 intVal):--- 代码 --

String stringVar = " value of integer intVal = " + new Integer( intVal ).toString(); Log.d(TAG, stringVar); --- code end ---

String stringVar = " 整数值 intVal = " + new Integer( intVal ).toString(); Log.d(TAG, stringVar); ---代码结束---

LogCat is very useful. You can add the LogCat window in Eclipse by doing this "Window -> Show View -> Other -> Android -> Logcat"

LogCat 非常有用。您可以通过执行此“窗口 -> 显示视图 -> 其他 -> Android -> Logcat”在 Eclipse 中添加 LogCat 窗口

回答by Pim Reijersen

The Android logging system provides a mechanism for collecting and viewing system debug output. Logs from various applications and portions of the system are collected in a series of circular buffers.

Android 日志系统提供了一种收集和查看系统调试输出的机制。来自各种应用程序和系统部分的日志被收集在一系列循环缓冲区中。

Logcat can be accessed using the command line. More information is in logcat(at Android Developers).

可以使用命令行访问 Logcat。更多信息在logcat(在 Android Developers)。

If you're using Eclipseand the Android plugin for Eclipse, it's available in the Debug perspective. More (unofficial) information about this is in Debugging in Android using Eclipse.

如果您使用Eclipse和用于 Eclipse 的 Android 插件,它在 Debug 透视图中可用。更多(非官方)信息在Debugging in Android using Eclipse 中

回答by Force

Logcat is some kind of file where all debug information and errors are stored. You can simply access it by either using the command "adb shell logcat" in a terminal on your developer machine with the development sdk or download an app like "alogcat" from the market.

Logcat 是一种存储所有调试信息和错误的文件。您可以通过在带有开发 sdk 的开发人员机器上的终端中使用命令“adb shell logcat”或从市场下载类似“alogcat”的应用程序来简单地访问它。

Like mthpvg and Pratik said, it is really handy and you can write your own messages in it.

就像 mthpvg 和 Pratik 所说的那样,它真的很方便,您可以在其中编写自己的消息。

回答by mthpvg

When you run your applications in debug you can have details on why they are crashing, plus if you want to write in it you can :

当您在调试中运行您的应用程序时,您可以获得有关它们崩溃原因的详细信息,此外,如果您想在其中写入,您可以:

Log.i(String tag, String msg);

回答by Yel

Logcat - used for debugging purposes Print different messages to Logcat using android.util.Log class

Logcat - 用于调试目的使用 android.util.Log 类将不同的消息打印到 Logcat

Syntax: Log.d(String tag, String message) Sample:

语法:Log.d(String tag, String message) 示例:

Log.d("LIFECYCLE","onCreate was called");

Other methods:

其他方法:

Log.i(String tag, String message);//i = information
Log.e(String tag, String message);//e = error
Log.w(String tag, String message);//w = warning

回答by chirag

I think the best explanation is in How to add LogCat?

我认为最好的解释是如何添加 LogCat?