这篇博客我们来分析logging.h提供的功能,引用这个文件可以#include <android-base/logging.h>,而这个文件在logging.cpp中实现。
首先我们来看下其注释:提供了一个c++ stream的接口,而且PLOG会打印出具体的错误,还支持logcat,stderr,dmesg的打印。
//
// Google-style C++ logging.
//
// This header provides a C++ stream interface to logging.
//
// To log:
//
// LOG(INFO) << "Some text; " << some_value;
//
// Replace `INFO` with any severity from `enum LogSeverity`.
//
// To log the result of a failed function and include the string
// representation of `errno` at the end:
//
// PLOG(ERROR) << "Write failed";
//
// The output will be something like `Write failed: I/O error`.
// Remember this as 'P' as in perror(3).
//
// To output your own types, simply implement operator<< as normal.
//
// By default, output goes to logcat on Android and stderr on the host.
// A process can use `SetLogger` to decide where all logging goes.
// Implementations are provided for logcat, stderr, and dmesg.
// This header also provides assertions:
//
// CHECK(must_be_true);
// CHECK_EQ(a, b) << z_is_interesting_too;
// NOTE: For Windows, you must include logging.h after windows.h to allow the
// following code to suppress the evil ERROR macro:
我们来看下这个头文件,使用之前必须先调用InitLogging函数,这里有三个Logger可供选择,KernelLogger、StderrLogger、LogdLogger,而在android系统下默认是LogdLogger。
void KernelLogger(LogId, LogSeverity, const char*, const char*, unsigned int, const char*);
void StderrLogger(LogId, LogSeverity, cons