上一章提到的是在Android系统中,以C语言格式方式进行log输出。本章就来讲讲c++语言格式的。
std::cout<<"This is a c++ log"<<std::endl;
在Android中也同样提供了类似的接口
LOG(INFO)<<"This is a c++ log from Android.";
不同的是不需要后加 std::endl 来告知一行结束。在Android的log系统中,天然的就认为一个LOG就对应一行内容。
在 Android 中,有着非常多的子系统,所以 Android 的 LOG 系统是支持多个buffer的,即不同类型的log写入不同的buffer中。它所支持的log类型可以简单的使用对应版本的 logcat 工具查看
board:/ # logcat -h
Usage: logcat [options] [filterspecs]
General options:
-b, --buffer=<buffer> Request alternate ring buffer(s):
main system radio events crash default all
Additionally, 'kernel' for userdebug and eng builds, and
'security' for Device Owner installations.
Multiple -b parameters or comma separated list of buffers are
allowed. Buffers are interleaved.
Default -b main,system,crash,kernel.
在c++语言风格的log接口中是没办法选择buffer输出的,它们默认被输出到 main buffer中去。
手头需要做的事有轻重缓急,log中的信息所代表的事项也同样如此。下面是Android log 系统的几个级别
//system\libbase\include\android-base\logging.h
namespace android {
namespace base {
...
enum LogSeverity {
VERBOSE,
DEBUG,
INFO,
WARNING,
ERROR,
FATAL_WITHOUT_ABORT, // For loggability tests, this is considered identical to FATAL.
FATAL,
...
};
}
};
前面也说了,c++风格的LOG接口只支持打印到main buffer,所以和上面的log级别组合也就如下几种
//system\libbase\include\android-base\logging.h
#define LOG(severity) LOGGING_PREAMBLE(severity) && LOG_STREAM(severity)
LOG(VERBOSE)
LOG(DEBUG)
LOG(INFO)
LOG(WARNING)
LOG(ERROR)
LOG(FATAL_WITHOUT_ABORT)
LOG(FATAL)
不同级别的log使用场景可以参考上一章节。
上面我们所说的 main/system/radio buffer实际上都是来自于logd的内部缓存,即属于logd这个进程。
但输出log到kernel中,则需要使用到kmsg了。kmsg大家应该更加的熟悉,因为linux存在时间可比Android悠久的多,它属于linux kernel的log子系统,Android系统是基于linux,所以除了Android系统本身规划的这些log外。还有一套linux kernel的log系统,它暴露的设备节点如下
board:/ # ls /dev/kmsg -Z
u:object_r:kmsg_device:s0 /dev/kmsg
Android还是一如既往的周到,提供了切换接口
//file:system\libbase\include\android-base\logging.h
LogFunction SetLogger(LogFunction&& logger);
切换kernel log
SetLogger(android::base::KernelLogger);
其中KernelLogger定义如下
// Log to the kernel log (dmesg).
void KernelLogger(LogId log_buffer_id, LogSeverity severity, const char* tag, const char* file, unsigned int line, const char* message);
在代码中,调用了如上接口后,在其之后的log都会被打印到/dev/kmsg中。我们可以通过dmesg来获取。
同样的,我们也可以将log定向到标准输出中
SetLogger(android::base::StdioLogger);
cc_binary {
name: "logPrintCppStyle",
srcs: [
"*.cpp",
],
shared_libs: [
"libbase",
],
cppflags: [
"-Wno-unused-parameter",
],
}
C语言风格的log打印接口,只使用了库 libbase,所以只要包含它即可。
#define LOG_TAG "logPrintCppStyle"
#include
#include //from libbase
#include
#include
#include
int main(int argc, char* argv[])
{
/*
1.print the log to stdio but not logd
board:/ # logcat -s logPrintCppStyle&
[1] 4971
board:/ # logPrintCppStyle
LOG(INFO):write INFO level to main buffer
*/
//android::base::InitLogging(nullptr, android::base::StdioLogger);
/**
* 2. print the log to kernel log buffer but not logd
* board:/ # logPrintCppStyle
* board:/ # --------- beginning of kernel
* 11-25 18:22:11.924 4975 4975 I logPrintCppStyle: LOG(INFO):write INFO level to main buffer
* board:/ # dmesg|grep logPrintCpp
* [15331.396227] logPrintCppStyle: LOG(INFO):write INFO level to main buffer
*/
//android::base::InitLogging(nullptr, android::base::KernelLogger);
/**
* 3.default:
* board:/ # logPrintCppStyle
* --------- beginning of main
* 11-25 18:26:59.983 4980 4980 I logPrintCppStyle: LOG(INFO):write INFO level to main buffer
*/
/**
* 4.Control the log to be shown by its level
* 4.1 INFO is the default level. So VERBOSE don't shows in default.
* board:/ # logPrintCppStyle
* 11-24 19:07:43.577 2894 2894 I logPrintCppStyle: LOG(INFO):write log
* 11-24 19:07:43.578 2894 2894 W logPrintCppStyle: LOG(WARNING):write log
* 11-24 19:07:43.578 2894 2894 E logPrintCppStyle: LOG(ERROR):write log
* 11-24 19:07:43.578 2894 2894 F logPrintCppStyle: LOG(FATAL_WITHOUT_ABORT):write log
*
* board:/ # setprop log.tag.logPrintCppStyle V
* board:/ # logPrintCppStyle
* 11-24 19:08:12.676 2925 2925 V logPrintCppStyle: LOG(VERBOSE):write log
* 11-24 19:08:12.677 2925 2925 D logPrintCppStyle: LOG(DEBUG):write log
* 11-24 19:08:12.677 2925 2925 I logPrintCppStyle: LOG(INFO):write log
* 11-24 19:08:12.677 2925 2925 W logPrintCppStyle: LOG(WARNING):write log
* 11-24 19:08:12.677 2925 2925 E logPrintCppStyle: LOG(ERROR):write log
* 11-24 19:08:12.677 2925 2925 F logPrintCppStyle: LOG(FATAL_WITHOUT_ABORT):write log
*
* board:/ # setprop log.tag.logPrintCppStyle I
* board:/ # logPrintCppStyle
* 11-24 19:09:17.451 2929 2929 I logPrintCppStyle: LOG(INFO):write log
* 11-24 19:09:17.451 2929 2929 W logPrintCppStyle: LOG(WARNING):write log
* 11-24 19:09:17.451 2929 2929 E logPrintCppStyle: LOG(ERROR):write log
* 11-24 19:09:17.451 2929 2929 F logPrintCppStyle: LOG(FATAL_WITHOUT_ABORT):write log
*
* board:/ # setprop log.tag.logPrintCppStyle E
* board:/ # logPrintCppStyle
* 11-24 19:09:40.640 2931 2931 E logPrintCppStyle: LOG(WARNING):write log
* 11-24 19:09:40.640 2931 2931 F logPrintCppStyle: LOG(FATAL_WITHOUT_ABORT):write log
*
* board:/ # setprop log.tag.logPrintCppStyle F
* board:/ # logPrintCppStyle
* 11-24 19:09:47.405 2933 2933 F logPrintCppStyle: LOG(FATAL_WITHOUT_ABORT):write log
*/
LOG(VERBOSE)<<"LOG(VERBOSE):write log";
LOG(DEBUG)<<"LOG(DEBUG):write log";
LOG(INFO)<<"LOG(INFO):write log";
LOG(WARNING)<<"LOG(WARNING):write log";
LOG(ERROR)<<"LOG(ERROR):write log";
//LOG(FATAL_WITHOUT_ABORT)<<"LOG(FATAL_WITHOUT_ABORT):write log";
//LOG(FATAL)<<"LOG(FATAL):write log";
/**
* 5. using PLOG to show the detial error when error occurs
* 11-24 19:17:49.677 2941 2941 E logPrintCppStyle: PLOG(ERROR):write log: No such file or directory
*/
open("/dev/fakeDev", O_APPEND);
PLOG(ERROR) << "PLOG(ERROR):write log";
/**
* 6.control the location where log is shown. /dev/dmesg or logd's main buffer
* board:/ # logPrintCppStyle
* 11-24 19:20:31.142 2943 2943 V logPrintCppStyle: LOG(VERBOSE):write log
* 11-24 19:20:31.143 2943 2943 D logPrintCppStyle: LOG(DEBUG):write log
* 11-24 19:20:31.143 2943 2943 I logPrintCppStyle: LOG(INFO):write log
* 11-24 19:20:31.143 2943 2943 W logPrintCppStyle: LOG(WARNING):write log
* 11-24 19:20:31.143 2943 2943 E logPrintCppStyle: LOG(ERROR):write log
* 11-24 19:20:31.143 2943 2943 F logPrintCppStyle: LOG(FATAL_WITHOUT_ABORT):write log
* 11-24 19:20:31.143 2943 2943 E logPrintCppStyle: PLOG(ERROR):write log: No such file or directory
* 11-24 19:20:31.143 2943 2943 I logPrintCppStyle: set StdioLogger as Logger...
* LOG(INFO):write log
*/
LOG(INFO)<<"set StdioLogger as Logger...";
SetLogger(android::base::StdioLogger);
LOG(INFO)<<"LOG(INFO):write log";
SetLogger(android::base::KernelLogger);
/**
* 7. making the crash in the application
* 11-24 19:22:38.611 2958 2958 I crash_dump64: performing dump of process 2955 (target tid = 2955)
* 11-24 19:22:38.642 417 417 I logd : logdr: UID=0 GID=0 PID=2958 n tail=0 logMask=8 pid=2955 start=0ns deadline=0ns
* 11-24 19:22:38.648 417 417 I logd : logdr: UID=0 GID=0 PID=2958 n tail=0 logMask=1 pid=2955 start=0ns deadline=0ns
* 11-24 19:22:38.641 2958 2958 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
* 11-24 19:22:38.641 2958 2958 F DEBUG : Build fingerprint: 'Fake/full_board_t/board:13/TP1A.220624.014/eng.flagstaff.20220920.145750:userdebug/test-keys'
* 11-24 19:22:38.641 2958 2958 F DEBUG : Revision: '0'
* 11-24 19:22:38.641 2958 2958 F DEBUG : ABI: 'arm64'
* 11-24 19:22:38.641 2958 2958 F DEBUG : Timestamp: 2022-11-24 19:22:38.613264983+0800
* 11-24 19:22:38.641 2958 2958 F DEBUG : Process uptime: 2s
* 11-24 19:22:38.642 2958 2958 F DEBUG : Cmdline: logPrintCppStyle
* 11-24 19:22:38.642 2958 2958 F DEBUG : pid: 2955, tid: 2955, name: logPrintCppStyl >>> logPrintCppStyle <<<
* 11-24 19:22:38.642 2958 2958 F DEBUG : uid: 0
* 11-24 19:22:38.642 2958 2958 F DEBUG : tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE)
* 11-24 19:22:38.642 2958 2958 F DEBUG : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
* 11-24 19:22:38.642 2958 2958 F DEBUG : Abort message: 'LOG(FATAL_WITHOUT_ABORT):write log'
* 11-24 19:22:38.642 2958 2958 F DEBUG : x0 0000000000000000 x1 0000000000000b8b x2 0000000000000006 x3 0000007ffea7f850
* 11-24 19:22:38.642 2958 2958 F DEBUG : x4 000000000000000a x5 000000000000000a x6 000000000000000a x7 7f7f7f7f7f7f7f7f
* 11-24 19:22:38.642 2958 2958 F DEBUG : x8 00000000000000f0 x9 0000007361352a80 x10 0000000000000001 x11 0000007361393760
* 11-24 19:22:38.642 2958 2958 F DEBUG : x12 0000007ffea7eb34 x13 0000000000000002 x14 0000000000000000 x15 00000073613568e2
* 11-24 19:22:38.642 2958 2958 F DEBUG : x16 0000007361400d58 x17 00000073613dc2a0 x18 00000073633e4000 x19 0000000000000b8b
* 11-24 19:22:38.642 2958 2958 F DEBUG : x20 0000000000000b8b x21 00000000ffffffff x22 0000007362f63000 x23 0000000000000000
* 11-24 19:22:38.642 2958 2958 F DEBUG : x24 0000000000000000 x25 0000000000000000 x26 0000000000000000 x27 0000000000000000
* 11-24 19:22:38.643 2958 2958 F DEBUG : x28 0000000000000000 x29 0000007ffea7f8d0
* 11-24 19:22:38.643 2958 2958 F DEBUG : lr 0000007361384248 sp 0000007ffea7f830 pc 0000007361384274 pst 0000000000001000
* 11-24 19:22:38.643 2958 2958 F DEBUG : backtrace:
* 11-24 19:22:38.643 2958 2958 F DEBUG : #00 pc 0000000000053274 /apex/com.android.runtime/lib64/bionic/libc.so (abort+164) (BuildId: 2909e25171905ab2aa55000ddb487289)
* 11-24 19:22:38.643 2958 2958 F DEBUG : #01 pc 00000000000063fc /system/lib64/liblog.so (__android_log_default_aborter+12) (BuildId: ea3eb93b960dede93d1fb67c42ed7273)
* 11-24 19:22:38.643 2958 2958 F DEBUG : #02 pc 0000000000016a50 /system/lib64/libbase.so (android::base::LogMessage::~LogMessage()+352) (BuildId: 805c1dfe4ea9454d03b5d1626665b3f0)
* 11-24 19:22:38.643 2958 2958 F DEBUG : #03 pc 00000000000015dc /system/bin/logPrintCppStyle (main+1404) (BuildId: f7c3609dd3aa7216053ac5cd10d3df82)
* 11-24 19:22:38.643 2958 2958 F DEBUG : #04 pc 000000000004b650 /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+96) (BuildId: 2909e25171905ab2aa55000ddb487289)
*/
//LOG(FATAL)<<"LOG(FATAL):write log";
/**
* 8.
* 11-27 12:37:17.677 5706 5706 V logPrintCppStyle: LOG(VERBOSE):write log
* 11-27 12:37:17.677 5706 5706 D logPrintCppStyle: LOG(DEBUG):write log
* 11-27 12:37:17.677 5706 5706 I logPrintCppStyle: LOG(INFO):write log
* 11-27 12:37:17.678 5706 5706 W logPrintCppStyle: LOG(WARNING):write log
* 11-27 12:37:17.678 5706 5706 E logPrintCppStyle: LOG(ERROR):write log
* 11-27 12:37:17.678 5706 5706 E logPrintCppStyle: PLOG(ERROR):write log: No such file or directory
* 11-27 12:37:17.678 5706 5706 I logPrintCppStyle: set StdioLogger as Logger...
* 11-27 12:37:17.687 5706 5706 F logPrintCppStyle: Check failed: false == true (false=0, true=1)
* error information:
* 11-27 12:37:17.724 5709 5709 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
* 11-27 12:37:17.724 5709 5709 F DEBUG : Build fingerprint: 'Fake/full_board_t/board:13/TP1A.220624.014/eng.flagstaff.20220920.145750:userdebug/test-keys'
* 11-27 12:37:17.724 5709 5709 F DEBUG : Revision: '0'
* 11-27 12:37:17.724 5709 5709 F DEBUG : ABI: 'arm64'
* 11-27 12:37:17.724 5709 5709 F DEBUG : Timestamp: 2022-11-27 12:37:17.707826659+0800
* 11-27 12:37:17.724 5709 5709 F DEBUG : Process uptime: 1s
* 11-27 12:37:17.724 5709 5709 F DEBUG : Cmdline: logPrintCppStyle
* 11-27 12:37:17.724 5709 5709 F DEBUG : pid: 5706, tid: 5706, name: logPrintCppStyl >>> logPrintCppStyle <<<
* 11-27 12:37:17.724 5709 5709 F DEBUG : uid: 0
* 11-27 12:37:17.724 5709 5709 F DEBUG : tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE)
* 11-27 12:37:17.725 5709 5709 F DEBUG : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
* 11-27 12:37:17.725 5709 5709 F DEBUG : Abort message: 'Check failed: false == true (false=0, true=1) '
* 11-27 12:37:17.725 5709 5709 F DEBUG : x0 0000000000000000 x1 000000000000164a x2 0000000000000006 x3 0000007fde3c3c90
* 11-27 12:37:17.725 5709 5709 F DEBUG : x4 000000000000000a x5 000000000000000a x6 000000000000000a x7 7f7f7f7f7f7f7f7f
* 11-27 12:37:17.725 5709 5709 F DEBUG : x8 00000000000000f0 x9 0000007864688a80 x10 0000000000000001 x11 00000078646c9760
* 11-27 12:37:17.725 5709 5709 F DEBUG : x12 0000007fde3c2f74 x13 0000000000000002 x14 0000000000000000 x15 000000786468c8e2
* 11-27 12:37:17.725 5709 5709 F DEBUG : x16 0000007864736d58 x17 00000078647122a0 x18 0000007868288000 x19 000000000000164a
* 11-27 12:37:17.725 5709 5709 F DEBUG : x20 000000000000164a x21 00000000ffffffff x22 0000007867a27000 x23 00000058c8e3fb8e
* 11-27 12:37:17.725 5709 5709 F DEBUG : x24 00000058c8e3fc17 x25 00000058c8e3fc1a x26 00000058c8e3fc6c x27 00000058c8e3fbb3
* 11-27 12:37:17.725 5709 5709 F DEBUG : x28 00000058c8e3fc8c x29 0000007fde3c3d10
* 11-27 12:37:17.725 5709 5709 F DEBUG : lr 00000078646ba248 sp 0000007fde3c3c70 pc 00000078646ba274 pst 0000000000001000
* 11-27 12:37:17.725 5709 5709 F DEBUG : backtrace:
* 11-27 12:37:17.725 5709 5709 F DEBUG : #00 pc 0000000000053274 /apex/com.android.runtime/lib64/bionic/libc.so (abort+164) (BuildId: 2909e25171905ab2aa55000ddb487289)
* 11-27 12:37:17.725 5709 5709 F DEBUG : #01 pc 00000000000063fc /system/lib64/liblog.so (__android_log_default_aborter+12) (BuildId: ea3eb93b960dede93d1fb67c42ed7273)
* 11-27 12:37:17.725 5709 5709 F DEBUG : #02 pc 0000000000016a50 /system/lib64/libbase.so (android::base::LogMessage::~LogMessage()+352) (BuildId: 805c1dfe4ea9454d03b5d1626665b3f0)
* 11-27 12:37:17.725 5709 5709 F DEBUG : #03 pc 000000000000131c /system/bin/logPrintCppStyle (main+700) (BuildId: dc17c42573ba586fece229f605ff661a)
* 11-27 12:37:17.726 5709 5709 F DEBUG : #04 pc 000000000004b650 /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+96) (BuildId: 2909e25171905ab2aa55000ddb487289)
*/
CHECK_EQ(false, true);
return EXIT_SUCCESS;
}
上面的例子大致包含了如下几种用法
a)使用接口SetLogger设置log的输出位置,其中 InitLogging 的功能和它是类似的,只不过更加自由,可以重新设置abort级别的log输出。
b)输出各级别的log
c)PLOG的使用,这个还是比较有意思的,因为他会直接把错误码直接转换成人类可阅读的形式输出log,下面是例子
/**
* 5. using PLOG to show the detial error when error occurs
* 11-24 19:17:49.677 2941 2941 E logPrintCppStyle: PLOG(ERROR):write log: No such file or directory
*/
open("/dev/fakeDev", O_APPEND);
PLOG(ERROR) << "PLOG(ERROR):write log";
d)FATAL级别和CHECK_XX系列的接口,前者会直接造成程序进入abort分支,导致程序异常退出。后者在条件满足的条件下和前者表现完全一致
/**
* 8.
* 11-27 12:37:17.677 5706 5706 V logPrintCppStyle: LOG(VERBOSE):write log
* 11-27 12:37:17.677 5706 5706 D logPrintCppStyle: LOG(DEBUG):write log
* 11-27 12:37:17.677 5706 5706 I logPrintCppStyle: LOG(INFO):write log
* 11-27 12:37:17.678 5706 5706 W logPrintCppStyle: LOG(WARNING):write log
* 11-27 12:37:17.678 5706 5706 E logPrintCppStyle: LOG(ERROR):write log
* 11-27 12:37:17.678 5706 5706 E logPrintCppStyle: PLOG(ERROR):write log: No such file or directory
* 11-27 12:37:17.678 5706 5706 I logPrintCppStyle: set StdioLogger as Logger...
* 11-27 12:37:17.687 5706 5706 F logPrintCppStyle: Check failed: false == true (false=0, true=1)
* error information:
* 11-27 12:37:17.724 5709 5709 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
* 11-27 12:37:17.724 5709 5709 F DEBUG : Build fingerprint: 'Fake/full_board_t/board:13/TP1A.220624.014/eng.flagstaff.20220920.145750:userdebug/test-keys'
* 11-27 12:37:17.724 5709 5709 F DEBUG : Revision: '0'
* 11-27 12:37:17.724 5709 5709 F DEBUG : ABI: 'arm64'
* 11-27 12:37:17.724 5709 5709 F DEBUG : Timestamp: 2022-11-27 12:37:17.707826659+0800
* 11-27 12:37:17.724 5709 5709 F DEBUG : Process uptime: 1s
* 11-27 12:37:17.724 5709 5709 F DEBUG : Cmdline: logPrintCppStyle
* 11-27 12:37:17.724 5709 5709 F DEBUG : pid: 5706, tid: 5706, name: logPrintCppStyl >>> logPrintCppStyle <<<
* 11-27 12:37:17.724 5709 5709 F DEBUG : uid: 0
* 11-27 12:37:17.724 5709 5709 F DEBUG : tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE)
* 11-27 12:37:17.725 5709 5709 F DEBUG : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
* 11-27 12:37:17.725 5709 5709 F DEBUG : Abort message: 'Check failed: false == true (false=0, true=1) '
* 11-27 12:37:17.725 5709 5709 F DEBUG : x0 0000000000000000 x1 000000000000164a x2 0000000000000006 x3 0000007fde3c3c90
* 11-27 12:37:17.725 5709 5709 F DEBUG : x4 000000000000000a x5 000000000000000a x6 000000000000000a x7 7f7f7f7f7f7f7f7f
* 11-27 12:37:17.725 5709 5709 F DEBUG : x8 00000000000000f0 x9 0000007864688a80 x10 0000000000000001 x11 00000078646c9760
* 11-27 12:37:17.725 5709 5709 F DEBUG : x12 0000007fde3c2f74 x13 0000000000000002 x14 0000000000000000 x15 000000786468c8e2
* 11-27 12:37:17.725 5709 5709 F DEBUG : x16 0000007864736d58 x17 00000078647122a0 x18 0000007868288000 x19 000000000000164a
* 11-27 12:37:17.725 5709 5709 F DEBUG : x20 000000000000164a x21 00000000ffffffff x22 0000007867a27000 x23 00000058c8e3fb8e
* 11-27 12:37:17.725 5709 5709 F DEBUG : x24 00000058c8e3fc17 x25 00000058c8e3fc1a x26 00000058c8e3fc6c x27 00000058c8e3fbb3
* 11-27 12:37:17.725 5709 5709 F DEBUG : x28 00000058c8e3fc8c x29 0000007fde3c3d10
* 11-27 12:37:17.725 5709 5709 F DEBUG : lr 00000078646ba248 sp 0000007fde3c3c70 pc 00000078646ba274 pst 0000000000001000
* 11-27 12:37:17.725 5709 5709 F DEBUG : backtrace:
* 11-27 12:37:17.725 5709 5709 F DEBUG : #00 pc 0000000000053274 /apex/com.android.runtime/lib64/bionic/libc.so (abort+164) (BuildId: 2909e25171905ab2aa55000ddb487289)
* 11-27 12:37:17.725 5709 5709 F DEBUG : #01 pc 00000000000063fc /system/lib64/liblog.so (__android_log_default_aborter+12) (BuildId: ea3eb93b960dede93d1fb67c42ed7273)
* 11-27 12:37:17.725 5709 5709 F DEBUG : #02 pc 0000000000016a50 /system/lib64/libbase.so (android::base::LogMessage::~LogMessage()+352) (BuildId: 805c1dfe4ea9454d03b5d1626665b3f0)
* 11-27 12:37:17.725 5709 5709 F DEBUG : #03 pc 000000000000131c /system/bin/logPrintCppStyle (main+700) (BuildId: dc17c42573ba586fece229f605ff661a)
* 11-27 12:37:17.726 5709 5709 F DEBUG : #04 pc 000000000004b650 /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+96) (BuildId: 2909e25171905ab2aa55000ddb487289)
*/
CHECK_EQ(false, true);
打印到logd中的log和C语言形式的log一样,也是支持根据log级别做有选择的方式进行输出的。但对于输出到标准输出以及kmsg的情况则是不适用的。
board:/ # setprop log.tag.logPrintCppStyle V
board:/ # logPrintCppStyle
LOG(INFO):write log
11-27 17:20:19.197 5914 5914 V logPrintCppStyle: LOG(VERBOSE):write log
11-27 17:20:19.197 5914 5914 D logPrintCppStyle: LOG(DEBUG):write log
11-27 17:20:19.197 5914 5914 I logPrintCppStyle: LOG(INFO):write log
11-27 17:20:19.197 5914 5914 W logPrintCppStyle: LOG(WARNING):write log
11-27 17:20:19.197 5914 5914 E logPrintCppStyle: LOG(ERROR):write log
11-27 17:20:19.197 5914 5914 E logPrintCppStyle: PLOG(ERROR):write log: No such file or directory
11-27 17:20:19.197 5914 5914 I logPrintCppStyle: set StdioLogger as Logger...
11-27 17:20:19.206 5914 5914 F logPrintCppStyle: Check failed: false == true (false=0, true=1)
Aborted
board:/ # setprop log.tag.logPrintCppStyle E
board:/ # logPrintCppStyle
11-27 17:20:24.767 5923 5923 E logPrintCppStyle: LOG(ERROR):write log
11-27 17:20:24.767 5923 5923 E logPrintCppStyle: PLOG(ERROR):write log: No such file or directory
11-27 17:20:24.775 5923 5923 F logPrintCppStyle: Check failed: false == true (false=0, true=1)
Aborted