有时候一些应用程序的日志输出是通过printf之类的标准函数输出的,logcat不能捕获到这些日志。
一个技巧是使用logwrapper命令来执行这些应用程序,logwrapper可以把标准输出重定向到logcat中去。
Usage: logwrapper [-x] BINARY [ARGS ...] Forks and executes BINARY ARGS, redirecting stdout and stderr to the Android logging system. Tag is set to BINARY, priority is always LOG_INFO. -x: Causes logwrapper to SIGSEGV when BINARY terminates fault address is set to the status of wait()
Source for logwrapper is at: system/core/logwrapper/logwrapper.c
例如:
在adb shell下
root@android:/ ps
ps的结果只在当前控制台下输出,要想把ps的结果输出到adb log中去,可以使用:
root@android:/ logwrapper ps
这样adb logcat就能捕获到ps的输出了.
例如:
在init.rc里面的程序
service LicenseManager /system/bin/logwrapper /system/bin/LicenseManager
class core
user root
group root
oneshot
这样LicenseManager 的程序输出就到logcat里面了.另外,如果你想把logcat里面的输出打印到终端.
你可以用到一个console.
service LicenseManager /system/bin/logwrapper /system/bin/LicenseManager
class core
user root
group root
+console
oneshot
这样信息就会打印到终端.
另外如果执行程序是脚本,可以在脚本里面设置
logcat -s /system/bin/gps.sh > /dev/kmsg
同样地,logcat 信息也可以打印到终端上.
但有一点请注意:在脚本里logcat命令不能加&后台运行命令.
否则自动运行程序,是打印不出任何信息的.