glog的使用
使用单例进行调用
class GlogSingle
{
public:
static GlogSingle* get_instance()
{
static GlogSingle clog;
return &clog;
}
bool cfgGlog(const char* node_name = "default", const char* log_dir = "log", const uint16_t level= google::INFO );
private:
GlogSingle(){};
~GlogSingle()
{
google::ShutdownGoogleLogging();
};
};
glog 参数配置
bool GlogSingle::cfgGlog(const char* node_name, const char* log_dir, const uint16_t level)
{
google::InitGoogleLogging(node_name);
FLAGS_log_dir = "./";
FLAGS_logtostderr =false;
FLAGS_timestamp_in_logfile_name = false;
FLAGS_alsologtostderr = false;
FLAGS_colorlogtostderr =true;
FLAGS_stderrthreshold = google::WARNING;
FLAGS_logbuflevel = google::ERROR;
FLAGS_log_prefix = true;
FLAGS_logbufsecs =0;
FLAGS_max_log_size = 2;
FLAGS_stop_logging_if_full_disk =true;
google::EnableLogCleaner(1);
LOG(INFO) << "Hello,cfgGlog!";
return true;
}
bool initGlog(std::string name, std::string path, Level level)
{
return GlogSingle::get_instance()->cfgGlog(name.c_str(), path.c_str(), level);
}