Skip to main content

Log Library Usage

Example:

// Include header file:
#include "log/log_api.hpp"
// Built-in custom level macros
#define LOG_DEBUG LOG(PDEBUG)
#define LOG_INFO LOG(PINFO)
#define LOG_WARNING LOG(PWARNING)
#define LOG_ERROR LOG(PERROR)
#define LOG_FATAL LOG(PFATAL)

// Print level:
// DEBUG INFO WARNING ERROR FATAL levels increase in order
//1 Set Plugin Log to be saved in the current Plugin's data/log directory during initialization, with total size 10M and 3 files
xcore_api::log::InitLogAPI("log",10,3);

LOG_INFO<<"hello world";
// Users can also use more g3log macros:
LOG(INFO)<<"hello world";

Conditional judgment: Print log when condition is true
LOG_IF(level, boolean_expression)
LOG_IF(ERROR, (1 < 2)) << "If true this message will be logged";

Print frequency control:
LOG_EVERY_N Record once every N times
for(int i = 0;i<100;++i)
LOG_EVERY_N(DEBUG, 100)<<i<<" i only log once"

Note: It is strongly recommended that users use the custom macros in log_api. These custom macros will output logs to the specified Plugin directory, while native g3log will output logs together with Controller logs, requiring viewing Plugin logs in the Controller logs. For more advanced usage, please refer to the macros defined in the header file.