EasyLogging ++ Study Notes (1) - Brief Introduction

For programmers who have experience in the development, execution log recording program is a necessary thing. By viewing and analyzing log information, not only can effectively help us debugger, and when the program officially released to run, but can help us to quickly and accurately locate the problem. At this age of open source, we do not need to write their own set of log database, open source version has been a lot. Unfortunately, in the current open source C ++ library journal, and not using a dominant share of the, I used before log4cplus and GLog , both libraries are more mature, but also a lot of online tutorials, so always I liked to use these two log database.

 

Some time ago, I came across on GitHub another open-source C ++ logging library was just a cursory study, the results actually let me put it down, it is Easylogging ++. And log4cplus and glog compared, Easylogging biggest feature is that it is only a ++ header files, and without any external dependencies, which I've never seen a logging library can do so lightweight but also take into account the performance. In addition, Easylogging ++ very simple to use, and also supports the configuration file, provides a powerful ability to custom log format also provides support for third-party libraries, STL containers. Faced with such a cool open source log, how can not learn! ! !

 

Easylogging ++ project on GitHub open source Address: https://github.com/easylogging/easyloggingpp

 

Functional characteristics

  • Highly configurable
  • the speed is very fast
  • And the type of security thread
  • Cross-platform
  • Custom Log mode
  • Conditions logs and occasionally log
  • Performance Tracking
  • Detailed logging
  • Interrupt processing
  • Auxiliary CHECK macro
  • STL log
  • Log third-party libraries (such as Qt, boost, wxWidgets)
  • Scalability
  • Debug Support Function
  • System logging
  • perror style log
  • C ++ style flow operator log
  • C language printf-style log
  •  ……
 
Imprint
 

As of this writing, the latest Easylogging ++ version V9.80, if the compiler does not support C ++ 11, it can not be compiled. For Visual Studio series, it must be VS2012 or later or job. If still in VS2010, VS2008, VS2005 junior partner, consider using EasyLogging ++ V8.91 version. It should be noted that the different versions will vary in use and function support. In particular, all of the records in this series to learn, apply only to Easylogging ++ version V9.80. In addition, all demo code that appears in this series of articles are compiled using Visual Studio 2013 64Bit Windows 7 system under test is.

 

Quick

 

As previously mentioned, Easylogging ++ very simple to use, simple to the point? Here we are given an example on GitHub Code:

#include "easylogging++.h"  
  
INITIALIZE_EASYLOGGINGPP  
  
int main(int argv, char* argc[]) {  
   LOG(INFO) << "My first info log using default logger";  
   return 0;  
}  

Only a few lines of sample code, the role of each line of code at a glance:

  • It contains easylogging ++. H header files
  • Use a macro INITIALIZE_EASYLOGGINGPP  initialization
  • Use macro LOG (INFO) to start logging
It is that simple, just three steps to complete your logging. It should be particularly noted that the initialization macros INITIALIZE_EASYLOGGINGPP must be used and can only be used once, otherwise it will produce a compilation error. The best place where this initialization macro program entry where the file is located on the top of the function, immediately after the code header file contains.
 
Custom Log
 
Easylogging ++ powerful custom log format capability is beyond doubt, we can through the configuration file, configuration parameters, etc. to configure the macro definition to define what you want the log format. The following is an example of a configuration file from the log defined by: 
#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;  
}  

 

Profile my_log.conf which reads 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  
Generated out of such a profile by logging would be very neat, and log information is saved to different files, but also to the standard output window. as follows:
 

See here, I believe for those who previously used a similar log4cplus small partners such as logs or glog library, in fact, has been fully started using Easylogging ++, and the rest are some of the details or ++ extensions of Easylogging Features, these It will gradually be recorded later in the study. If, like me, you have seen and liked Easylogging ++ friends, let us work together to understand Easylogging ++ and apply it into the actual development of it.

 

Reference website: https://blog.csdn.net/xie1xiao1jun/article/details/54572803

Guess you like

Origin www.cnblogs.com/2018shawn/p/11905143.html