glog简单使用

来源:互联网 发布:数据更新维护机制 编辑:程序博客网 时间:2024/06/05 01:01
git clone https://github.com/google/glog.git/ .

or:

svn co https://github.com/google/glog.git/ .

windows: download cmake (www.cmake.org) generate cmake .sln file(glog.sln).

linux: cmake . && make && make install


simple testcase:

#include <windows.h>#define GOOGLE_GLOG_DLL_DECL#define GLOG_NO_ABBREVIATED_SEVERITIES#include "glog/logging.h"#include <string>#include <iostream>int main(int argc, const char** argv){// Start google log system:FLAGS_log_dir = "e:\\Logs";google::InitGoogleLogging(argv[0]);//google::SetLogDestination(google::GLOG_INFO, "e:\\Logs\\INFO_");google::SetStderrLogging(google::GLOG_WARNING);//google::SetLogFilenameExtension("log_");FLAGS_colorlogtostderr = true;  // Set log colorFLAGS_logbufsecs = 0;  // Set log output speed(s)FLAGS_max_log_size = 1024;  // Set max log file sizeFLAGS_stop_logging_if_full_disk = true;  // If disk is fullchar str[20] = "hello glog!";LOG(INFO) << str;std::string cStr = "hello google!";LOG(INFO) << cStr;LOG(INFO) << "info test" << "hello log!";  //输出一个Info日志LOG(WARNING) << "warning test";  //输出一个Warning日志LOG(ERROR) << "error test";  //输出一个Error日志std::string strInput;std::cin >> strInput;while (strInput != "E" && strInput != "e"){LOG(ERROR) << strInput;std::cin >> strInput;}google::ShutdownGoogleLogging();return 0;}

windows:

Configuration Properties->C/C++->Additional Include Directories:    E:\study\glog\glog_src\trunk\src\windows

Configuration Properties->Linker->Additional Library Directories: E:\study\glog\glog_build\Debug\

Configuration Properties->Linker->Additional Dependences:glog.lib;%(AdditionalDependencies)

make sure Configuration Properties->C/C++->Code Generation->Runtime Library is the same as the library named glog in glog.sln(MTD/MT or MDD/MD)