centos下使用glog

安装git

yum install git 

安装glog

1 git clone https://github.com/google/glog.git
2 cd glog
3 ./autogen.sh
4 ./configure                   //可以不配置文件夹--prefix=path(install)
5 make
6 make install					//安装到/usr/local/lib路径下

在执行第三步骤的时候可能会遇到一些问题,:

在这里插入图片描述
安装以下工具解决

yum install autoconf
yum install automake
yum install libtool

使用glog

#include <string>
#include <iostream>
#include "glog/logging.h"   // glog 头文件
#include "glog/raw_logging.h"

int main(int argc, char** argv){
    // FLAGS_log_dir=".";   //设置log目录  没有指定则输出到控制台
    FLAGS_logtostderr = 1;  //输出到控制台
    google::InitGoogleLogging(argv[0]);    // 初始化

    std::string test = "this is test";
    int i = 2, number = 8;

    LOG(INFO) << "it is info";     // 打印log:“hello glog.  类似于C++ stream。
    LOG_IF(INFO, number > 10) << "number >  10"; 
    LOG_IF(INFO, number < 10) << "number <  10";
    for(i=0; i<20 ;i++){
        LOG_EVERY_N(INFO, 5) << "log i = " << i;
    }

    LOG(WARNING) << "It is error info"; 
    LOG(ERROR) << "It is error info"; 

    DLOG(INFO) << "it is debug mode";
    DLOG_IF(INFO, number > 10) << "debug number > 10";  
    // DLOG_EVERY_N(INFO, 10) << "log i = " << i;
    RAW_LOG(INFO, "it is pthread log");


    return 0;
}

编译(需要把、usr/local/lib的库拷贝到test_main.cpp同级文件夹)
在这里插入图片描述

g++ test_main.cpp ./lib/libglog.a -std=c++11 -DDEBUG -lpthread -o sample
//g++ test_main.cpp ./lib/libglog.a -I./include  -std=c++11 -DDEBUG -lpthread -o sample

参考

Linux C++ glog使用

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值