0

I'm building a really simple Android project in ADT and using Maven. I have included both the slf4j-api and slf4j-android dependencies and I can see that everything is compiling properly. However, when I run or debug the application on my Nexus One, I don't see any log output. Is there a specific place I should be looking for these logs or should they be coming out in the Eclipse console?

For reference, here's my main activity:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import android.app.ListActivity;
import android.os.Bundle;

public class HomeActivity extends ListActivity {

private static Logger logger = LoggerFactory.getLogger(HomeActivity.class);

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        logger.debug("onCreate");
    }
}
Naftuli Kay
  • 87,710
  • 93
  • 269
  • 411
  • I would say its not possible, as you are using slf4j-android. I dont think you can use normal slf4j with some other impl like log4j or logback. If you would have 2 slf4, its up to JVM which one would be loaded, so both wont work. If you want to log only to eclipse console use normal SLF4J + IMPL (log4j or logback). – To Kra Feb 09 '15 at 16:49

3 Answers3

2

Android by default tells slf4j-android to not to log debug messages, and log4j is polite enough to honor that. Use the impolite https://github.com/mvysny/slf4j-handroid instead :)

Martin Vysny
  • 3,088
  • 28
  • 39
  • Is it able to switch from Log to System.out if same module executed in JVM? – surlac Jan 27 '17 at 02:36
  • Sorry, that is currently not possible, and is probably against the slf4j philosophy that slf4j-impl should be a small library tailored to one logging backend only. – Martin Vysny Apr 13 '17 at 10:30
1

I use slf4j as well for logging. The log output shows up on the LogCat window. I'm not sure if there's a way to see it in the Eclipse console. In the Eclipse top-level menu, navigate to: Window -> Show View -> Other. When the dialog appears, expand "Android", and select "LogCat". It doesn't show up by default, unfortunately.

HTH,

Kevin

ktambascio
  • 434
  • 4
  • 17
  • Thanks, that did the trick. I thought it might be doing something like that. It's kind of weird that it formats it in the way it does, but hey, it works :) – Naftuli Kay Feb 03 '11 at 18:22
1

You may want to have a look at using slf4j together with android-logging-log4j. Also see log4j support in Android.

Community
  • 1
  • 1
Rolf Kulemann
  • 213
  • 2
  • 6