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