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

相关内容

热门资讯

耕秀才遇到兵打一成语 耕秀才遇到兵打一成语秀才遇到兵,有理说不清。你好。。。。 秀才遇到兵,有理说不清。。。。。谜底:蛮不...
女性的气质和优雅,都是如何培养... 女性的气质和优雅,都是如何培养的?腹有诗书气自华,多读书多有一些想法,确实会影响女性的气质,多注意一...
征求一些好听的青春励志流行歌曲... 征求一些好听的青春励志流行歌曲!杨培安的我相信,很励志哦励志一首就够了,何必这么复杂,酸酸甜甜就是我...
推荐几本专情的玄幻或武侠小说 推荐几本专情的玄幻或武侠小说(经典的言情也可以)东方血修 除了这个好像专情的还真不多斗罗大陆,寸芒...
有谁知道湖南台的宫锁心玉是哪部... 有谁知道湖南台的宫锁心玉是哪部小说改编的,去看清穿小说的鼻祖《步步惊心》吧。以那里的剧情为主题改编的...
入字拼音怎么拼写 入字拼音怎么拼写拼音: [rù] 入字共有2画,笔画顺序为: 撇、捺。● 入释斗带义:◎ 进,由外到...
“她拥有难以想象的强大力量”用... “她拥有难以想象的强大力量”用英语怎么翻译She has the hard-imagined str...
穿越四大无人区可可西里第八天里... 穿越四大无人区可可西里第八天里歌曲叫什么名字颠藏线过不了可可西里吧。。。。。可可西里在藏北,青海。颠...
帝王攻略广播剧是否完结? 帝王攻略广播剧是否完结?暂时没有,但是已经有了好几期,可以在b站上听
穿越到隋朝的小说 穿越到隋朝的小说主角穿越到一个大臣家名字有个天字最后他带着他的护卫风雨雷电穿越了拯救大唐妹妹隋主天下...
痛不欲生的意思 痛不欲生的意思形容非常痛苦
历史上到底有没有貂蝉啊?还有貂... 历史上到底有没有貂蝉啊?还有貂蝉喜欢谁貂蝉这个人存在的可能性不大,因为中国古代的小说和流行文本是文化...
求几句甜言蜜语?… 求几句甜言蜜语?…爱情和情歌一样,最高境界是余音袅袅。最凄美的不是报仇雪恨,而是遗憾。最好的爱情,必...
恋爱禁止的世界有第二季吗 恋爱禁止的世界有第二季吗这基本没有第2季了,动漫结局和漫画完全2个样子,我看作者是草草结束了,别想了...
夕上面加个横,右边一个撇横再加... 夕上面加个横,右边一个撇横再加个横折折折钩,再两个撇读什么 ?"殇"是这个字吧?shang殇(sha...
经常锻炼身体的人和不经常锻炼身... 经常锻炼身体的人和不经常锻炼身体的人有什么区别经常健身的:今年看着30岁 十年以后还是30岁;不经...
谁能帮我写首表白的藏头诗,对象... 谁能帮我写首表白的藏头诗,对象:卢雅楠雅曲勿轻弹,声声拨相思。楠船难载爱,情浓压水低。我情随风去,寻...
如何能避免造口业,佛教网 如何能避免造口业,佛教网不懂的不去评论 不说任何事物的是非!!身口业都是因为意业推动的,只要坚持修持...
有没有鸣人穿越海贼王世界的小说... 有没有鸣人穿越海贼王世界的小说?鸣人穿越在海贼王世界和路飞一起!现在要最少出上百章(篇)的小说!鸣人...
一陂春水浇花身,花影妖娆各占春... 一陂春水浇花身,花影妖娆各占春,纵被春风吹作血,绝胜南陌碾成尘,是谁的诗王安石的《北陂杏花》王安石 ...