Glog learning notes

  • 简介

        glog 是基于C++98标准实现的应用程序级别的日志记录库,它提供了基于C++风格的IO流和各种辅助宏的日志记录api。

  • 编译 (Test with Ubuntu & CMake, same below)

       在选定的目录下,执行以下命令:

git clone https://github.com/google/glog.git
cd glog && mkdir build && cd build
cmake ..
make -j4 && sudo make install 
  • 测试

        在选定的目录下,执行以下命令:

mkdir glog_test && cd glog_test && mkdir build
touch glog_test.cpp CMakeLists.txt

        使用编辑器编辑以下内容到glog_test.cpp & CMakeLists.txt:      

// glog_test.cpp

#include 
#include 

int main(int argc, char **argv)
{
    FLAGS_alsologtostderr = true;
    google::InitGoogleLogging(argv[0]);

    LOG(INFO) << "This is an INFO";
    LOG(WARNING) << "This is a WARNING";
    LOG(ERROR) << "This is an ERROR";
    LOG(FATAL) << "This is a FATAL";

    google::ShutdownGoogleLogging();
    return 0;
}
# CMakeLists.txt

cmake_minimum_required (VERSION 3.16)
project (glog_test VERSION 1.0)

find_package (glog 0.6.0 REQUIRED)

add_executable (glog_test glog_test.cpp)
target_link_libraries (glog_test glog::glog)

         在选定的目录下,执行以下命令:

cd build && cmake .. && make
./glog_test

        得到以下输出:         

Glog learning notes_第1张图片

你可能感兴趣的:(Learning,Notes,c++)