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

相关内容

热门资讯

流失美国79载 国宝文物子弹库... 当地时间5月16日晚,由美国史密森尼学会国立亚洲艺术博物馆返还的“子弹库帛书”第二卷“五行令”和第三...
在沪举办百余场活动,擦亮投资者... 转自:新华财经第七个“5·15全国投资者保护宣传日”期间,建行上海市分行积极响应号召,践行“金融为民...
智光电气年产值50亿元新型储能... (转自:储能早知道)  5月14日,智光电气宣布其年产值达50亿元的智光新型储能产业园正式竣工投产。...
以军突发大规模袭击,代号为“基... 美国总统特朗普15日在卡塔尔出席一场商业圆桌会议时再次宣称,美国可以“接管加沙”,并将其打造为一个“...
以为会变胖,实际很减肥的5个习... 许多人减肥主打一个:既要“躺平”又要稳赢。今天这篇文章,认真看一看,也许真能在减肥道路上“躺赢”。习...
交通银行与工业和信息化部火炬中... 转自:北京商报5月16日,交通银行与工业和信息化部火炬中心联合发起的走进千企万户“五个一”专项行动之...
模块化建筑“智”造未来,“绿色... 来源:风财讯在塔吊林立的工地中,工人手持平板电脑操控机械臂,精准拼接模块,当传统建房模式,还在晒图纸...
又见“长存利少”!多家银行存款...   低利率时代,“存五年不如存一年”愈发常见。  作为商业银行最为普遍的揽储工具,一直以来,定期存款...
600671、002092、6... 一些风险警示公司通过内控整改、积极自救等方式改善经营能力,多举措化解退市或其他风险。5月16日晚间,...
巴西首次报告商业养殖场高致病性... 巴西农业部16日发布公报,确认该国南部一处商业养殖场出现家禽感染高致病性禽流感病毒病例。这是该国首次...
一女子被医院强制带走治疗!官方... 关于“禹州女子被医院急救人员强制带走治疗”的调查处置情况通报5月16日上午11:05,禹州市120急...
廖伟煜正式履新光大信用卡中心总... 21世纪经济报道记者张欣 北京报道5月16日,国家金融监督管理总局网站发布任职资格批复显示,北京金融...
晋祠博物馆“流动博物馆”进校园... 中新网太原5月17日电 (记者 胡健)日前,晋祠博物馆联合太原市双塔西街小学共同开展“流动博物馆进校...
一箭六星!朱雀二号改遥二火箭成... 转自:北京日报客户端5月17日12时12分,朱雀二号改进型遥二运载火箭在东风商业航天创新试验区发射升...
俞敏洪履新职 转自:京报网_北京日报官方网站 【#俞敏洪履新职#】#俞敏洪任徐霞客文旅学院院长#据《无锡日报...
美国拉斯维加斯一健身房发生枪击... 来源:中国新闻网 中新网5月17日电 据美联社报道,美国警方表示,当地时间16日下午,美国拉斯维加斯...
消息称 realme 真我 N... IT之家 5 月 17 日消息,博主@数码闲聊站 今日爆料称realme 真我 Neo7 Turbo...
OPPO发布首台“直播手机”,... 5月15日,OPPO在广东珠海正式推出备受瞩目的Reno14系列手机,搭载更AI的ColorOS 1...
联合国呼吁以色列与胡塞武装立即... 转自:央视当地时间16日,联合国秘书长发言人办公室呼吁以色列及胡塞武装停止敌对行动。在人道主义援助不...
广东多举措防御强降雨 中新网广州5月17日电 (记者 王坚)据广东省应急管理厅17日消息,该省近期仍有强降雨,相关部门要做...