Skip to content

Androlog quickstart

cescoffier edited this page Sep 22, 2010 · 6 revisions

This page explains how to use Androlog.

Create an Android application project

First, you need an Android project. You can use Eclipse, Ant or Maven to achieve this task. In this tutorial, we just use Eclipse. So, make sure you have the Android Eclipse plugin installed as well as the Android SDK.

In Eclipse, Go to File - New - Project... - Android / Android Project.

Fill the new project wizard.

You can create a test project too, but it is not required.

Add Androlog to the project

Create a lib folder in your project, and copy the androlog jar in this folder. Right-clic on the jar, and add it to the build path.

For Ant, you just need to add androlog to the project classpath. For maven, just add androlog as a dependency (in the compile scope).

Using Androlog

Open the MyActivity.java file, and add the Androlog initialization and a log message:

package my.application;

import de.akquinet.android.androlog.Log;
import android.app.Activity;
import android.os.Bundle;

public class MyActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Initializes androlog
        // This will read the /sdcard/my.application.properties file
        Log.init(this);

        // Log a messgage
        Log.i(this, "This is a logged message");

        setContentView(R.layout.main);
    }
}

Run the application

Now it's time to run the application. Right clic on the project - Run As - Run as Android application. This will start an emulator, and start the application

Open logcat, either in the console (adb logcat) or in Eclipse. You will not see the logged message ! Indeed, the log is disabled by default, this allows to simply remove all logged messages on regular/user phones. But don't worry, configuring logging is really simple.

Androlog configuration

Create a file named my.application.properties. The name is the application's package name + .properties. Edit the file to obtain:

androlog.active=true
Push the file on the root of the sdcard: adb push my.application.properties /sdcard/

Then restart the application. Look at logcat. You will see the logged message:

I/ActivityManager(   51): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=my.application/.MyActivity }
I/my.application.MyActivity(  215): This is a logged message
I/ActivityManager(   51): Displayed activity my.application/.MyActivity: 174 ms (total 174 ms)

That's it ! You now have a way to enable / disable the logging in a pretty simple way without modifying your application code. Androlog provides a lot of configuration option, so don't forget to look to the documentation.