Add Logging to your Android App

How to Add Logging to your Android App

Log was was added in API Level 1

1. Create an Android app, if you don't already have one.

2. In the MainActivity.java file, add the below import

import android.util.Log;

3. Right after your public class, declare this String to use throughout your class. Replace MyAppName with the name of your Android App. Replace MyActivity with the name of your activity.

private static final String TAG = "MyAppName.MyActivity";

4. In the onCreate method, add this line where you would like.

Log.e(TAG, "This is some message.");

5. Compile and run!

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    ...
    <application android:icon="@drawable/icon"
        android:debuggable="true"
6. These are the different types of Logs that can be used.

Log.e - error (will work without debuggable = true set in AndroidManifest.xml)
Log.d - debug
Log.i - informational
Log.v - verbose
Log.w - warning (will work without debuggable = true set in AndroidManifest.xml)
Log.wtf - what a terrible failure (a failure that should never happen) (Added in API Level 8) This will print a stacktrace also.

Resources:
http://developer.android.com/reference/android/util/Log.html
http://mobile.tutsplus.com/tutorials/android/logcat_android-sdk/
http://stackoverflow.com/questions/2952140/android-how-do-i-mark-my-app-as-debuggable