glog使用

参考文章
glog使用与功能修改
Glog使用介绍与源码分析

我自己的初始化函数

void Glog_Init(int argc, char** argv)
{
  google::InitGoogleLogging(argv[0]);

  std::string glog_target_dir = "/okagv/glog/navigation";
  std::string glog_whole_dir = getenv("HOME") + glog_target_dir;
  std::string glog_info_dir = glog_whole_dir + "/INFO/";
  std::string glog_warning_dir = glog_whole_dir + "/WARNING/";
  std::string glog_error_dir = glog_whole_dir + "/ERROR/";
  std::string glog_fatal_dir = glog_whole_dir + "/FATAL/";

  std::vector<std::string> glog_dir;
  glog_dir.push_back(glog_whole_dir);
  glog_dir.push_back(glog_info_dir);
  glog_dir.push_back(glog_warning_dir);
  glog_dir.push_back(glog_error_dir);
  glog_dir.push_back(glog_fatal_dir);

  google::SetLogDestination(google::GLOG_INFO, glog_info_dir.c_str());
  google::SetLogDestination(google::GLOG_WARNING, glog_warning_dir.c_str());
  google::SetLogDestination(google::GLOG_ERROR, glog_error_dir.c_str());
  google::SetLogDestination(google::GLOG_FATAL, glog_fatal_dir.c_str());

  FLAGS_logbufsecs = 0; //缓冲日志输出,默认为30秒,此处改为立即输出
  FLAGS_max_log_size = 5; //最大日志大小为 5MB
  FLAGS_stop_logging_if_full_disk = true; //当磁盘被写满时,停止日志输出

  for (auto it : glog_dir) {
    DIR* _tmp_pDir;
    // FLAGS_log_dir = glog_whole_dir;
    if (!(_tmp_pDir = opendir(it.c_str()))) {
      LOG(INFO) << "glog filedir doesn't Exist! create it";

      if (!createFolder(it)) {
        LOG(INFO) << "create glog filedir failed";
      }
      closedir(_tmp_pDir);
    }
  }

  google::ParseCommandLineFlags(&argc, &argv, true);
}

程序每进入50次打印一次log

LOG_EVERY_N(INFO,50) << " add odom";
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

可峰科技

生活不易

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值