CPP(c++) google glog
Google 轻量级,入门简单,功能较全,线程安全,支持自定义。
参考: https://www.jianshu.com/p/a576ed1c2cd3
int main(int argc,char* argv[]) { google::InitGoogleLogging(argv[0]);// 初始化 FLAGS_logtostderr = false; //设置日志消息是否转到标准输出而不是日志文件 FLAGS_alsologtostderr = false; //设置日志消息除了日志文件之外是否去标准输出 FLAGS_log_prefix = true; //设置日志前缀是否应该添加到每行输出 FLAGS_log_dir = "./log"; //预创建好 //google::SetStderrLogging(google::GLOG_FATAL); for(int i = 0 ; i < 100 ; i++) { LOG(INFO) << "Hello,info! "; LOG(ERROR) << "Hello erroe! " <<i; LOG(WARNING) << "Hello,waring! "<<i<<"+"<<i<<"="<<i+i; //LOG(FATAL) << "Hello,fatal! "; } google::ShutdownGoogleLogging();//关闭log return 0; }
CHECK* 宏定义: #define CHECK(a) \ if(!(a)) { \ LOG(ERROR) << " CHECK failed " << endl \ << #a << "= " << (a) << endl; \ abort(); \ } \ #define CHECK_NOTNULL(a) \ if( NULL == (a)) { \ LOG(ERROR) << " CHECK_NOTNULL failed " \ << #a << "== NULL " << endl; \ abort(); \ } #define CHECK_NULL(a) \ if( NULL != (a)) { \ LOG(ERROR) << " CHECK_NULL failed " << endl \ << #a << "!= NULL " << endl; \ abort(); \ } #define CHECK_EQ(a, b) \ if(!((a) == (b))) { \ LOG(ERROR) << " CHECK_EQ failed " << endl \ << #a << "= " << (a) << endl \ << #b << "= " << (b) << endl; \ abort(); \ } #define CHECK_NE(a, b) \ if(!((a) != (b))) { \ LOG(ERROR) << " CHECK_NE failed " << endl \ << #a << "= " << (a) << endl \ << #b << "= " << (b) << endl; \ abort(); \ } #define CHECK_LT(a, b) \ if(!((a) < (b))) { \ LOG(ERROR) << " CHECK_LT failed " \ << #a << "= " << (a) << endl \ << #b << "= " << (b) << endl; \ abort(); \ } #define CHECK_GT(a, b) \ if(!((a) > (b))) { \ LOG(ERROR) << " CHECK_GT failed " << endl \ << #a <<" = " << (a) << endl \ << #b << "= " << (b) << endl; \ abort(); \ } #define CHECK_LE(a, b) \ if(!((a) <= (b))) { \ LOG(ERROR) << " CHECK_LE failed " << endl \ << #a << "= " << (a) << endl \ << #b << "= " << (b) << endl; \ abort(); \ } #define CHECK_GE(a, b) \ if(!((a) >= (b))) { \ LOG(ERROR) << " CHECK_GE failed " << endl \ << #a << " = "<< (a) << endl \ << #b << "= " << (b) << endl; \ abort(); \ } #define CHECK_DOUBLE_EQ(a, b) \ do { \ CHECK_LE((a), (b)+0.000000000000001L); \ CHECK_GE((a), (b)-0.000000000000001L); \ }while (0)