How to Debug an Android Application using LogCat – Part I
In this blog post, i’ll teach you on how to Debug an Android Application using LogCat. This blog helps newbie mostly on debugging an app before and after App publishing. So lets get Started.
What is LogCat?
LogCat is a command used for looking into the Logs generated from various programs running on Android application environment. This logcat can be used from ADB shell to view the logs. The Android Logging provides a mechanism for collecting and viewing system debug output. Every android log message has a tag and Priority associated with it.
- Tag: string indicating from which component the message originates.
- Priority: is one of the character values ordered from lowest to highest priority. LogCat has different levels of logging.
- V-Verbose(lowest priority)
- D-Debug
- I-Info
- W-Warning
- E-Error
- F-Fatal
- S-Silent
The developers can also write custom log messages.
To write log statements, you use the android.util.Log
class with the Log.v()
, Log.d()
, Log.i()
, Log.w()
, Log.e(), this is somewhat similar to Java applications, done by printing messages in the console window using System.out.println(String message) method.
The first parameter of these methods is the TAG and the second is the Message to Log. Basic Example of Logging custom log message.
</pre> <pre>import android.app.Activity; import android.os.Bundle; import android.util.Log; public class helloWorld extends Activity { /** Called when the activity is first created. */ private static final String TAG="geeks.gallery"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Log.d(TAG,"I'm Debugging Android Application"); } }</pre> <pre>
How to open LogCat window?
In Eclipse you can view the LogCat window by selecting Window -> Show View -> Other and choosing LogCat from the Android category.
ScreenShots:
LogCat displaying logs:
You can also filter Logs based on their Tag, pid or Log Level (Error, Warning, Info, Debug, Verbose) or you can define your own custom filter.
Now read my next blog on how to Debug an Android Application before and after publishing.
Hope this helpful. Your valuable comments are always welcomed. It will help to improve my post and understanding.
Related Posts
durga chiranjeevi
Latest posts by durga chiranjeevi (see all)
- Sharing Application Data Between Two Android Apps – Part III - April 8, 2015
- Sharing Application Data Between Two Android Apps – Part II - April 8, 2015
- Sharing Application Data Between Two Android Apps – Part I - April 8, 2015