Now Mayuyu to introduce a very useful tool, namely Glog. Like GFlags, are Google Open source tools, the difference is that Glog is used to print the log.
Contents
1. Glog Installation Steps
2. How to use Glog
1. Glog Installation Steps
You should first download the Glog installation package at the address below
Links:https://code.google.com/p/google-glog/downloads/list
Then unzip it and execute the following commands after entering the directory
(1)./configure
(2) Make
(3) Make install
The default installation path for . so files is/usr/local/lib, which requires a soft link to be established as follows
OK, the installation is completed here, you can rest assured that the use of.
2. How to use Glog
The logs in Glog are divided into 4 levels, i.e. INFO,WARNING,ERROR,FATAL, corresponding numbers 0, 1, 2, 3 respectively.
The corresponding level of the log is printed in the corresponding level of the log file. and high-level logs are printed at both this and low levels. For example, info
There will be warning levels of output.
Initialize parameters
Flags_log_dir Log Output Directory
Flags_v a custom vlog (m), the m value is less than the statement setting the value here to output
Flags_max_log_size maximum size per log file (MB level)
Flags_minloglevel the minimum level of the output log, that is, logs that are above or equal to this level will be output.
Output logs satisfying certain conditions, e.g. log_if (INFO, num_cookies >) << "Got lots of cookies";
Google::initgooglelogging ("Spider"); Set the file Name field in the log file name
Google::shutdowngooglelogging (); Stop Glog, with initgooglelogging () to use, no
This will cause a memory leak.
Glog is based on the process ID to differentiate the file, if you restart the program, the log file name will change.
Different categories of log storage path settings
Code:
#include <iostream> #include <string.h> #include <stdio.h> #include <glog/logging.h>using namespace Std;int Main (int argc, char **argv) {google::initgooglelogging (argv[0]); Flags_log_dir = "./log"; LOG (INFO) << "Mayuyu"; LOG (WARNING) << "Hello"; google::shutdowngooglelogging (); With Google::initgooglelogging (argv[0]); Use in pairs, otherwise memory leaks return 0;}
For reference
Http://www.cnblogs.com/tianyajuanke/archive/2013/02/22/2921850.html
Http://www.cppfans.org/1566.html
http://tudian2007.blog.163.com/blog/static/3156641320139176563617/
Use of Glog