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

Summary of commonly used multi-table modification statements in Mysql and Oracle

I saw this question in the SQL training question ...

The meaning of the 5 types of spaces in HTML

HTML provides five space entities with different ...

Detailed explanation of CSS elastic box flex-grow, flex-shrink, flex-basis

The functions of the three attributes flex-grow, ...

How to turn local variables into global variables in JavaScript

First we need to know the self-calling of the fun...

Implementation of local migration of docker images

I've been learning Docker recently, and I oft...

How to set MySQL foreign keys for beginners

Table of contents The role of foreign keys mysql ...

Use CSS content attr to achieve mouse hover prompt (tooltip) effect

Why do we achieve this effect? ​​In fact, this ef...

Detailed explanation of lazy loading and preloading of webpack

Table of contents Normal loading Lazy Loading Pre...

MySQL data types full analysis

Data Type: The basic rules that define what data ...

MySql index detailed introduction and correct use method

MySql index detailed introduction and correct use...

CentOS 6-7 yum installation method of PHP (recommended)

1. Check the currently installed PHP packages yum...

Detailed explanation of the data responsiveness principle of Vue

This article is mainly for those who do not under...

How to set an alias for a custom path in Vue

How to configure custom path aliases in Vue In ou...