glog

// #define GOOGLE_STRIP_LOG 1
#include <glog/logging.h>

#include <iostream>

int main(int argc, char** argv) {
  FLAGS_log_dir = "./log_dir";
  FLAGS_alsologtostderr = true;
  FLAGS_colorlogtostderr = true;
  google::InitGoogleLogging(argv[0]);
  // google::EnableLogCleaner(3); // keep your logs for 3 days
  // google::DisableLogCleaner();

  LOG(INFO) << "I am INFO!";
  LOG(WARNING) << "I am WARNING!";
  LOG(ERROR) << "I am ERROR!";
  // LOG(FATAL) << "I am FATAL!";
  // DLOG_EVERY_N()     // DEBUG 日志
  // VLOG_IF_EVERY_N()  // VERBOS 日志

  // 条件日志
  LOG_IF(INFO, true) << "log this if true";
  for (int i = 0; i < 4; i++) {
    LOG_EVERY_N(INFO, 2) << "log this every two times";
    LOG_IF_EVERY_N(INFO, true, 2)
        << "log this ervery twotimes if condition is true";
    LOG_FIRST_N(INFO, 2) << "only log N times";
  }

  // CHECK 宏,不受 NDEBUG 编译选项的约束
  CHECK(true) << "FATAL if true";
  // CHECK_EQ CHECK_GE CHECK_STREQ

  google::ShutdownGoogleLogging();
  return 0;
}

头文件 #include <glog/raw_logging.h>下的 RAW_XXX 为线程安全方法

posted @ 2023-01-11 21:03  某某人8265  阅读(137)  评论(0编辑  收藏  举报