AndroidT(13) -- C plus plus 语言格式的LOG输出(二)
创始人
2024-02-25 06:35:14
0

1.概览

  上一章提到的是在Android系统中,以C语言格式方式进行log输出。本章就来讲讲c++语言格式的。

std::cout<<"This is a c++ log"<

  在Android中也同样提供了类似的接口

LOG(INFO)<<"This is a c++ log from Android.";

  不同的是不需要后加 std::endl 来告知一行结束。在Android的log系统中,天然的就认为一个LOG就对应一行内容。

2. 打印LOG内容所属的类型

2.1 输出 Android系统的LOG到logd

  在 Android 中,有着非常多的子系统,所以 Android 的 LOG 系统是支持多个buffer的,即不同类型的log写入不同的buffer中。它所支持的log类型可以简单的使用对应版本的 logcat 工具查看

board:/ # logcat -h
Usage: logcat [options] [filterspecs]General options:-b, --buffer=       Request alternate ring buffer(s):main system radio events crash default allAdditionally, 'kernel' for userdebug and eng builds, and'security' for Device Owner installations.Multiple -b parameters or comma separated list of buffers areallowed. Buffers are interleaved.Default -b main,system,crash,kernel.

  在c++语言风格的log接口中是没办法选择buffer输出的,它们默认被输出到 main buffer中去。

2.2 打印内容所属的级别

  手头需要做的事有轻重缓急,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使用场景可以参考上一章节。

2.3 输出 Android系统的LOG到 kmsg

  上面我们所说的 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

2.4 切换LOG输出 – SetLogger

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

3.使用实例 – logPrintCppStyle

3.1 编译配置 – Android.bp

cc_binary {name: "logPrintCppStyle",srcs: ["*.cpp",],shared_libs: ["libbase",],cppflags: ["-Wno-unused-parameter",],
}

  C语言风格的log打印接口,只使用了库 libbase,所以只要包含它即可。

3.2 测试源码 – logPrintCppStyle.cpp


#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 logdboard:/ # logcat -s logPrintCppStyle&[1] 4971board:/ # logPrintCppStyleLOG(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);

4.使用属性控制log级别输出

  打印到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

相关内容

热门资讯

合合信息7月3日获融资买入83... 7月3日,合合信息涨0.03%,成交额1.02亿元。两融数据显示,当日合合信息获融资买入额839.0...
托普云农7月3日获融资买入18... 7月3日,托普云农涨6.67%,成交额2.98亿元。两融数据显示,当日托普云农获融资买入额1863....
科拜尔7月3日获融资买入87.... 7月3日,科拜尔涨0.35%,成交额3633.11万元。两融数据显示,当日科拜尔获融资买入额87.3...
博苑股份7月3日获融资买入76... 7月3日,博苑股份跌0.20%,成交额7766.12万元。两融数据显示,当日博苑股份获融资买入额76...
天和磁材7月3日获融资买入30... 7月3日,天和磁材跌1.05%,成交额3.27亿元。两融数据显示,当日天和磁材获融资买入额3044....
国货航7月3日获融资买入833... 7月3日,国货航涨0.15%,成交额1.29亿元。两融数据显示,当日国货航获融资买入额833.57万...
惠通科技7月3日获融资买入33... 7月3日,惠通科技涨0.21%,成交额5293.76万元。两融数据显示,当日惠通科技获融资买入额33...
首航新能7月3日获融资买入19... 7月3日,首航新能跌1.11%,成交额2.86亿元。两融数据显示,当日首航新能获融资买入额1995....
汉邦科技7月3日获融资买入55... 7月3日,汉邦科技涨1.44%,成交额5519.25万元。两融数据显示,当日汉邦科技获融资买入额55...
城市笙歌|千年瓷器纹样跃上潮流... 转自:上观新闻7月3日,“博物新消费:传统文化在消费场景中焕发新生”的主题活动在上海博物馆东馆举行。...