Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSLog equivalent for Android dev using Eclipse

Tags:

android

I am wondering if there is a syntax to print out something in the eclipse console windows. This is just like NSLog in xcode. Thank you

like image 837
BlackSoil Avatar asked Dec 31 '10 19:12

BlackSoil


1 Answers

Use the android.util.Log class http://developer.android.com/reference/android/util/Log.html.

For example:

import android.util.Log;

class Someclass {
    private static final String TAG = "Someclass";
    ...
    public boolean someMethod(int argument) {
        Log.i(TAG, "This is some information log");
        if (argument == 0) {
           Log.e(TAG, "Error argument is 0!!!");
           return false;
        }


        Log.w(TAG, "Warning returning default value");
        return true;
    }
};

The reason the TAG variable is assigned like that instead of something like: Somelcass.class.getSimpleName() is because the reflective method will cause the reflection metta data of the class to be loaded on initialisation, however, the 'preferred' method by android developers prevents that and hence saves CPU and initialisation time.

like image 157
langerra.com Avatar answered Sep 22 '22 10:09

langerra.com