0

I am working on an Android project with some classes that I plan to pull out as a pure Java.jar (to be used in other java related projects). In these pure Java classes, I use System.out to log. This is also an Android application though, so n my Android classes, I obviously use Log.

In monitoring the pure java classes, I can't get System.out to print out in my Eclipse logcat. I do see System.err though.

Does anyone know how to get System.out to display in LogCat in this fabled Log.i level?

Setup

  1. Nexus 7 - Android 4.4.4 - Stock
  2. Eclipse Kepler
  3. Android SDK 21
  4. Ubuntu 12.04 64 bit
  5. Monitoring all messages tab in Logcat, logcat set to verbose

I've Tried

adb root
adb shell start
adb shell setprop log.redirect-stdio true
adb shell stop
  • Logcat is set to verbose
  • Nothing in Console under Android or DDMS
Constantin
  • 16,812
  • 9
  • 34
  • 52

1 Answers1

0

Now you can send your Pure Java project logs into warning level for example...

    OutputStream os = new OutputStream() {

        @Override
        public synchronized void write(byte[] buffer, int offset, int len) {
            Log.w("blah", new String(buffer));
        }

        @Override
        public void write(int oneByte)
                throws IOException {
            // Not really sure what to do here...
        }
    };
    System.setOut(new PrintStream(os));
    System.out.println("Adam.");
TacB0sS
  • 10,106
  • 12
  • 75
  • 118
  • Except that now my pure java classes are linking to Android classes, specifically `Log` – Constantin Aug 28 '14 at 20:59
  • He wants to have a jar with classes that can be used in both Android and normal java projects, importing log will only work on Android and not in the normal java projects – WHDeveloper Aug 28 '14 at 22:09
  • True, but he can do this from the android project and it would apply to all the code running in the jvm... isn't that what he wants? – TacB0sS Aug 29 '14 at 09:53
  • I expect to pull out some of these classes into a purely Java based project that will be jarred as a library for use in future java projects not running on an Android JVM – Constantin Aug 29 '14 at 13:28
  • You need to write this code in your Android project, preferable in your CustomApplication.onCreate() or as a static block in your first activity. This has nothing to do with your code or how you break it into project, and will not have any effect on another pure Java project. – TacB0sS Aug 29 '14 at 16:08