android stdout

1.  in init.rc service , add console .

example:

service exa1 /system/bin/exa.sh

    class main

    user root

    console

         

2. in system/core/init/init.c:

    if (needs_console) {

            setsid();

            open_console();

        } else {

            zap_stdio();     //change zap_stdio() to open_console

        }

 

 

 

in c/cpp file , the printf can not send message to console , so to send log to logcat according below:

in *.c   or   *.cpp  or   *.h:

#include<android/log.h>

#include<cutils/log.h> 

#define LOGD(LOCAL_TAG,...)  __android_log_print(ANDROID_LOG_DEBUG, LOCAL_TAG, __VA_ARGS__)

 

 

3. By default, the Android system sends stdout and stderr

  (System.out and System.err) output to /dev/null. In

  processes that run the Dalvik VM, you can have the system write a copy of the output to the log

  file. In this case, the system writes the messages to the log using the log tags

  

setprop log.redirect-stdio true:

grep -irsn "redirect-stdio" .

./frameworks/base/docs/html/tools/debugging/debugging-log.jd:296:$ adb shell setprop log.redirect-stdio true

./frameworks/base/core/jni/AndroidRuntime.cpp:494:    property_get("log.redirect-stdio", propBuf, "");

 

frameworks/base/core/jni/AndroidRuntime.cpp:

  property_get("log.redirect-stdio", propBuf, "");

    if (strcmp(propBuf, "true") == 0) {

        logStdio = true;

    }

 

 if (logStdio) {

        /* convert stdout/stderr to log messages */

        opt.optionString = "-Xlog-stdio";

        mOptions.add(opt);

    }

 

 

4.  system/core/logwrapper/logwrapper.c:

  "Usage: logwrapper [-a] [-d] [-k] BINARY [ARGS ...]\n"

        "\n"

        "Forks and executes BINARY ARGS, redirecting stdout and stderr to\n"

        "the Android logging system. Tag is set to BINARY, priority is\n"

        "always LOG_INFO.\n"

        "\n"

        "-a: Causes logwrapper to do abbreviated logging.\n"

        "    This logs up to the first 4K and last 4K of the command\n"

        "    being run, and logs the output when the command exits\n"

        "-d: Causes logwrapper to SIGSEGV when BINARY terminates\n"

        "    fault address is set to the status of wait()\n"

        "-k: Causes logwrapper to log to the kernel log instead of\n"

        "    the Android system log\n");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值