download link:
Official website:
https://code.google.com/archive/p/google-glog/github:
https://github.com/google/glog
The glog library implements application-level logging. This library provides logging APIs based on C++-style streams and various helper macros.
The main function:
1. Parameter setting, setting flag parameters in the form of command line parameters to control logging behavior;
2. Severity classification, recording logs according to log severity classification;
3. Logging information can be recorded conditionally;
4. Conditional termination of the program. Abundant conditional judgment macros can preset program termination conditions;
5. Exception signal processing. Program exceptions, you can customize the exception handling process;
6, support the debug function. Can only be used in debug mode;
7, custom log information;
8, thread-safe logging method;
9, system-level logging;
10, google perror style log information;
11. Simplify the log string information.
glog installation and use under window
After downloading, unzip it, and use Visual Studio to open google-glog.sln. Generate a solution
Open sln and there will be several projects, libglog is a dynamic library, which generates dll, and libglog_static is a static library, which generates lib.
Install:
Method 1: Copy the libglog.dll and libglog.lib files to your project folder, and copy the glog directory under src\windows\ to your project file.
Method 2: You can also copy these two files to the system folder for global access.
1. Copy libglog.dll to C:\Program Files\Microsoft Visual Studio 14.0\VC\bin
2. Copy libglog.lib to C:\Program Files\Microsoft Visual Studio 14.0\VC\lib
3. Copy the glog directory to C:\Program Files\Microsoft Visual Studio 14.0\VC\include
test program
#include "glog/logging.h" #include <iostream> #include <vector> using namespace std; #pragma comment(lib,"libglog.lib") int main(int argc, char* argv[]) { // Initialize Google's logging library. google::InitGoogleLogging(argv[0]); google::SetLogDestination(google::INFO,"E://glog"); // Set log path INFO WARNING ERROR FATAL // ... char str[20] = "hello log!"; LOG(INFO) << "Found " << google::COUNTER <<endl; LOG(INFO) << str ;//<< " cookies"; LOG(WARNING) << "warning test"; // will output a Warning log LOG(ERROR) << "error test";//An Error log will be output system("pause"); return 0; }
Compilation possible problems:
glog compiled under vs2010 and
opened google-glog.sln
compiled
successfully
In the Debug folder, there are the files we want, such as libglog.dll libglog.lib, etc.
glog compile under vs2015
open google-glog.sln
compile
error 1: 'min' is not a member of std
Solution:
add header file#include<algorithm>
Error 2: warning C4005: "va_copy": macro redefinition
Solution:
Modify the file port.h, line 117 to:
#undef va_copy #define va_copy(dst, src) (dst) = (src)
Error 3:
error C2084: function 'int snprintf(char *const ,const size_t,const char *const ,…)' already has a body
c:\program files (x86)\windows kits\10\include\10.0.10150.0\ucrt \stdio.h(1932): note: see previous definition of "snprintf"
solution:
Modify the name of snprintf, such as snprintf_glog, if you want to change it all, you can use the big tomato plug-in, which is convenient and fast
Reference link:
https://blog.csdn.net/luyafei_89430/article/details/39497765
https://blog.csdn.net/wangshubo1989/article/details/53324586