栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

glog使用

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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 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";
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/738216.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号