欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

glog使用

时间:2023-05-31

参考文章
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";

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。