Skip to main content

log Library Usage

Example:

// Include header:
#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)

// Log levels:
// DEBUG, INFO, WARNING, ERROR, and FATAL increase in severity
// 1. During initialization, store plugin logs under the current plugin data/log directory; max total size 10 MB 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 logging: log when the condition is true
LOG_IF(level, boolean_expression)
LOG_IF(ERROR, (1 < 2)) << "If true this message will be logged";

Log frequency control:
LOG_EVERY_N logs once every N occurrences
for(int i = 0;i<100;++i)
LOG_EVERY_N(DEBUG, 100)<<i<<" i only log once"

Note: It is strongly recommended to use the custom macros in log_api, which write all logs to the designated plugin directory.

Native g3log writes logs together with controller logs, so plugin logs must be viewed in the controller log.

For advanced usage, see the macros defined in the header files.