版本0.3.5
1、安装
git clone https://github.com/google/glog.git
cd glog
./configure && make && make install
出现recipe for target 'logging_unittest' failed
先安装gflag
git clone https://github.com/gflags/gflags.git
cd gflag
mkdir build
cd build
cmake ..
make
sudo make install
sudo apt-get purge libgflags-dev
cmake中使用
set(INC_DIR /usr/local/include)
set(LINK_DIR /usr/local/lib)
include_directories(${INC_DIR})
link_directories(${LINK_DIR})
ADD_EXECUTABLE(app ${DIR_SRCS} ${PROJECT_SRCS})
target_link_libraries(app glog)
示例代码:
#include <glog/logging.h>
int main(int argc,char* argv[])
{
google::InitGoogleLogging(argv[0]); //初始化 glog
LOG(INFO) << "Hello,GOOGLE!";
}
查看
cat /tmp/app.INFO
Log file created at: 2019/08/12 11:13:54
Running on machine: user-System-Product-Name
Log line format: [IWEF]mmdd hh:mm:ss.uuuuuu threadid file:line] msg
I0812 11:13:54.847128 7906 main.cpp:11] Hello,GOOGLE!
打印到终端:
FLAGS_logtostderr = 1;