glog学习

转自:https://blog.csdn.net/jcjc918/article/details/51682853

1.介绍

glog 是 google 的一个 c++ 开源日志系统,轻巧灵活。https://github.com/google/glog.git

#include <glog/logging.h>

int main(int argc,char* argv[])
{
    google::InitGoogleLogging(argv[0]); //初始化 glog
    LOG(INFO) << "Hello,GOOGLE!";
}

编译运行:

glog g++ glog_test2.cpp -lglog -lgflags -lpthread -o glog_test #编译
glog ./glog_test

gcc 和 g++ 中库的链接顺序是从右往左进行,所以要把最基础实现的库放在最后,这样左边的 lib 就可以调用右边的 lib 中的代码。

指定日志文件的目录,默认会放在 /tmp 下。打印的日志信息:

I0703 22:04:05.242153  6569 glog_test2.cpp:7] Hello,GLOG!

I+日期 时:分:秒.微秒 线程号 源文件名:行数] 信息

2.日志级别 

https://cloud.tencent.com/developer/article/1683448

glog 将日志级别分为 4 种,分别是:

  • INFO:普通日志;
  • WARNING:告警日志;
  • ERROR:错误日志;
  • FATAL:严重错误日志,打印完日志后程序将会推出(os.Exit()

 

posted @ 2022-08-07 22:40  lypbendlf  阅读(45)  评论(0编辑  收藏  举报