System.out到Eclipse中的Android Logcat

时间:2014-08-28 18:21:25

标签: java android eclipse system.out

我正在开发一个Android项目,其中包含一些我打算作为纯Java.jar提取的类(用于其他java相关项目)。在这些纯Java类中,我使用System.out进行记录。这也是一个Android应用程序,所以在我的Android类中,我显然使用Log

在监视纯java类时,我无法在Eclipse logcat中打印出System.out。我确实看到了System.err

有没有人知道如何让这个传说中的System.out级别的Log.i显示在LogCat中?

设置

  1. Nexus 7 - Android 4.4.4 - 股票
  2. Eclipse Kepler
  3. Android SDK 21
  4. Ubuntu 12.04 64位
  5. 监控Logcat中的所有消息选项卡,logcat设置为verbose
  6. 我试过

    adb root
    adb shell start
    adb shell setprop log.redirect-stdio true
    adb shell stop
    
    • Logcat设置为详细
    • Android或DDMS下的控制台中没有任何内容

1 个答案:

答案 0 :(得分:0)

现在您可以将Pure Java项目日志发送到警告级别,例如......

    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.");