How to use glog log library in Linux environment

How to use glog log library in Linux environment

Generate Linux library

The Linux version uses centos7.3, compile and generate the library

  • 1. cd glog-0.3.3
  • 2. ./configure
  • 3. make

After make is completed, the corresponding library file will be generated under .lib

Using glog library under Linux

Linux uses static libraries for testing. Copy the static library libglog.a and the header files of src/glog to your own project directory, create the main.cpp file, and add the following code:

/********************************************************
Copyright (C), 2016-2018,
FileName: main
Description: Glog usage demo
************************************************************/
#include <stdio.h>
#include "glog/logging.h"
int main()
{
   //Initialization parameters FLAGS_logtostderr = FALSE; //TRUE: standard output, FALSE: file output FLAGS_alsologtostderr = TRUE; //Do you need standard output in addition to the log file FLAGS_colorlogtostderr = FALSE; //Standard output with color FLAGS_logbufsecs = 0; //Set the maximum number of seconds that can buffer logs, 0 means real-time output FLAGS_max_log_size = 10; //Log file size (unit: MB)
   FLAGS_stop_logging_if_full_disk = true; //Whether to log to disk when the disk is full google::InitGoogleLogging("mqttserver");
    google::SetLogDestination(google::GLOG_INFO,"./test");
    LOG(INFO) << "this is log";
    LOG(WARNING) << "this is warning";
    LOG(ERROR) << "this is error";
    google::ShutdownGoogleLogging();
}

Compile: g++ main.cpp -o main -L. -lglog -lpthread

Run: ./main The output is as follows:

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Detailed explanation of command to view log files in Linux environment
  • How to manually scroll logs in Linux system
  • Summary of 6 Linux log viewing methods
  • A simple method to implement Linux timed log deletion
  • Detailed introduction to logs in Linux system

<<:  Complete code for implementing the popular astronaut watch face based on JavaScript

>>:  Mysql uses the kill command to solve the deadlock problem (kill a certain SQL statement being executed)

Recommend

Detailed description of component-based front-end development process

Background <br />Students who work on the fr...

HTML+CSS+JS realizes the scrolling gradient effect of the navigation bar

Table of contents First look at the effect: accom...

Ways to improve MongoDB performance

MongoDB is a high-performance database, but in th...

Sharing the structure and expression principles of simple web page layout

Introduction to structure and performance HTML st...

Steps to create a CentOS container through Docker

Table of contents Preface Create a bridge network...

Analyzing ab performance test results under Apache

I have always used Loadrunner to do performance t...

Pitfall notes of vuex and pinia in vue3

Table of contents introduce Installation and Usag...

MySQL case when usage example analysis

First we create the database table: CREATE TABLE ...

Detailed explanation of how to use Tomcat Native to improve Tomcat IO efficiency

Table of contents Introduction How to connect to ...

How to implement form validation in Vue

1. Installation and use First, install it in your...

Steps for encapsulating element-ui pop-up components

Encapsulate el-dialog as a component When we use ...

A brief talk about MySQL pivot tables

I have a product parts table like this: part part...