开发者

What is LogCat in Eclipse?

开发者 https://www.devze.com 2023-03-31 04:24 出处:网络
What does LogCat do in Eclipse? How do I use it? I have never used the log cat before in Eclipse, s开发者_如何转开发o I don\'t understand.This is a nice and quick way to exchange information from th

What does LogCat do in Eclipse?

How do I use it? I have never used the log cat before in Eclipse, s开发者_如何转开发o I don't understand.


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

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.


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

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.

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");


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


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.

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


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


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

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.

String TAG = "AppName";

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

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

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

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


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.

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

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


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

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

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消