glog的使用

主要还是看官方文档吧

 

win32下,把#define GLOG_NO_ABBREVIATED_SEVERITIES 放到#include <windows.h>之前,具体说明文档中有说。

glog不支持分天滚动打印,是PID滚动打印,不过可以自己改源码定制需求:http://blog.csdn.net/tomisaboy/article/details/51418845

glog的LOG(LEVEL)是线程安全的

glog 不支持Unicode

glog跨DLL打印的时候,也需要初始化glog,然后再打印,不然不能。: http://ask.csdn.net/questions/346759?sort=id  https://github.com/google/glog/issues/83

 

简单的Demo:

 1 #include <windows.h>
 2 #include <glog/logging.h>
 3 
 4 int main(int argc, char *argv[]){
 5 
 6    // init glog
 7 
 8     FLAGS_logbufsecs =30;  //缓冲区超时,超过30秒,自动刷入log文件,设置为0是实时打印
 9         FLAGS_max_log_size =100;  //最大日志大小(MB)
10 
11         GLOG_logtostderr = false; //默认为false ,设置为true,log定向到stderr
12 
13         google::InitGoogleLogging(argv[0]);
14     google::SetLogDestination(google::GLOG_INFO, "./logs/info_");
15     google::SetLogDestination(google::GLOG_WARNING, "./logs/warning_");
16     google::SetLogDestination(google::GLOG_ERROR, "./logs/error_");
17 
18 
19     LOG(INFO) << "My Info";
20     LOG(WARNING) << "My WARNING";
21     LOG(ERROR) << "My Error";
22     
23 
24     return 0; 
25 }

 

 

 

 

 

references:

http://mengjh.blog.51cto.com/2860827/546766

http://www.cnblogs.com/tianyajuanke/archive/2013/02/22/2921850.html

posted @ 2017-03-05 19:15  foo__hack  阅读(1633)  评论(0编辑  收藏  举报