The open source address of easylogin + + project on Github: https://github.com/easylogging/easyloggingpp
Functional features
·Height configurable
·Very fast
·Thread and type safety
·Cross platform
·Custom log module
·Conditional log and accidental log
·Performance tracking
·Detailed log
·Interrupt processing
·Auxiliary CHECK macro
·STL log
·Third party library logs (such as Qt, boost, wxWidgets)
·Scalability
·Support Debug function
·System logging
·perror style log
·C + + stream operator style log
·C language printf style log
·...
Version Description
At the time of writing this article, the latest version of Easylogging + + is V9 80. If the compiler does not support C++11, it cannot be compiled. For Visual Studio Series, it must be VS2012 or above. If you still stay in the small partners of VS2010, VS2008 and VS2005, you can consider using Easylogging + + V8 Version 91. It should be noted that different versions have different usage methods and functional support. In particular, all learning records in this series are only applicable to easy logging + + version V9 80. In addition, all the demo codes in this series of articles are compiled and tested using Visual Studio 2013 under 64Bit Windows 7 system.
Quick use
The following is an example code given on GitHub:
#include "easylogging++.h" INITIALIZE_EASYLOGGINGPP int main(int argv, char* argc[]) { LOG(INFO) << "My first info log using default logger"; return 0; }
There are only a few lines of sample code, and the function of each line of code is clear at a glance:
·Contains easylogging + + H header file
·Use macro INITIALIZE_EASYLOGGINGPP initialization
·Use LOG(INFO) to start logging
It's that simple. It only takes three steps to complete your logging. It should be noted here that the initialization macro initializes_ Easyloggingpp must be used and can only be used once, otherwise compilation errors will occur. The best place to place this initialization macro is at the top of the file where the program entry function is located, followed by the code containing the header file.
Custom log
We can define the log format we want through configuration files, configuration parameters, configuration macro definitions, etc. The following is an example of using the configuration file to customize the log:
#include "easylogging++.h" INITIALIZE_EASYLOGGINGPP int main(int argc, char** argv) { el::Configurations conf("my_log.conf"); el::Loggers::reconfigureAllLoggers(conf); LOG(TRACE) << "***** trace log *****"; LOG(DEBUG) << "***** debug log *****"; LOG(ERROR) << "***** error log *****"; LOG(WARNING) << "***** warning log *****"; LOG(INFO) << "***** info log *****"; system("pause"); return 0; }
Where the configuration file is my_ log. The contents of conf are as follows:
* GLOBAL: ENABLED = true TO_FILE = true TO_STANDARD_OUTPUT = true FORMAT = "[%level | %datetime] | %msg" FILENAME = "log\\log_%datetime{%Y%M%d}.log" MILLISECONDS_WIDTH = 3 PERFORMANCE_TRACKING = false MAX_LOG_FILE_SIZE = 1048576 LOG_FLUSH_THRESHOLD = 0 * TRACE: FILENAME = "log\\trace_log_%datetime{%Y%M%d}.log" * DEBUG: FILENAME = "log\\debug_log_%datetime{%Y%M%d}.log" * FATAL: ENABLED = false * ERROR: FILENAME = "log\\error_log_%datetime{%Y%M%d}.log" * WARNING: FILENAME = "log\\warning_log_%datetime{%Y%M%d}.log" * INFO: FILENAME = "log\\info_log_%datetime{%Y%M%d}.log" * VERBOSE: ENABLED = false
The logs produced through such a configuration file will be very neat. At the same time, the log information will be saved in different files and output to the standard output window. As follows:
reference resources:
https://www.yuque.com/docs/share/cc65ebaa-f992-4d37-a104-6eb5dfac7001