1、简介
     glog 是google的开源日志系统,本质上是一个程序级记录日志信息的c++库,编程使用方式与c++的stream操作类似,例如:

LOG(INFO) << "Hello Glog";

2、安装
    下载连接:http://code.google.com/p/google-glog/
    安装:./configure; make; make install
3、日志严重等级
      glog可通过根据指定的严重性等级,来选择性记录日志。日志信息严重性等级按由低到高排列依次为:INFO, WARNING, ERROR, 和 FATAL四级。使用者可以在命令行中设置严重性等级门限值来控制日志的输出。

4、编程试用

#include<iostream>   
#include<stdlib.h>   
#include<stdio.h>   
#include<string>      

//glog   
#include<glog/logging.h>   

using namespace std;      

int main() {
    // HOME_PATH       
    string home = "/root/glog/";       
    
    //glog init       
    google::InitGoogleLogging(argv[0]);       
    
    string info_log = home + "/log/master_info_";       
    google::SetLogDestination(google::INFO, info_log.c_str());       
    
    string warning_log = home + "/log/master_warning_";       
    google::SetLogDestination(google::WARNING, warning_log.c_str());       
    
    string error_log = home + "/log/master_error_";       
    google::SetLogDestination(google::ERROR, error_log.c_str());       

    string fatal_log = home + "/log/master_fatal_";       
    google::SetLogDestination(google::FATAL, fatal_log.c_str());             
    
    LOG(INFO) << "Hello Glog" ;      

    return 0;   
}

5、编译:假设源文件命名为a.cpp

g++ a.cpp -o a -lglog -lpthread