PcapPlusPlus
Next
|
#include <Logger.h>
Public Types | |
enum | LogLevel { Error , Info , Debug } |
typedef void(* | LogPrinter) (LogLevel logLevel, const std::string &logMessage, const std::string &file, const std::string &method, const int line) |
Public Member Functions | |
LogLevel | getLogLevel (LogModule module) |
void | setLogLevel (LogModule module, LogLevel level) |
bool | isDebugEnabled (LogModule module) const |
void | setAllModulesToLogLevel (LogLevel level) |
void | setLogPrinter (LogPrinter printer) |
void | resetLogPrinter () |
std::string | getLastError () |
void | suppressLogs () |
void | enableLogs () |
bool | logsEnabled () const |
void | internalPrintLogMessage (std::ostringstream *logStream, Logger::LogLevel logLevel, const char *file, const char *method, int line) |
Static Public Member Functions | |
static std::string | logLevelAsString (LogLevel logLevel) |
static Logger & | getInstance () |
PcapPlusPlus logger manager. PcapPlusPlus uses this logger to output both error and debug logs. There are currently 3 log levels: Logger::Error, Logger::Info and Logger::Debug.
PcapPlusPlus is divided into modules (described in LogModule enum). The user can set the log level got each module or to all modules at once. The default is Logger::Info which outputs only error messages. Changing log level for modules can be done dynamically while the application is running.
The logger also exposes a method to retrieve the last error log message.
Logs are printed to console by default in a certain format. The user can set a different print function to change the format or to print to other media (such as files, etc.).
PcapPlusPlus logger is a singleton which can be reached from anywhere in the code.
Note: Logger::Info level logs are currently only used in DPDK devices to set DPDK log level to RTE_LOG_NOTICE.
pcpp::Logger::LogPrinter |
Log printer callback. Used for printing the logs in a custom way.
[in] | logLevel | The log level for this log message |
[in] | logMessage | The log message |
[in] | file | The source file in PcapPlusPlus code the log message is coming from |
[in] | method | The method in PcapPlusPlus code the log message is coming from |
[in] | line | The line in PcapPlusPlus code the log message is coming from |
|
inline |
Enable logs in all PcapPlusPlus modules
|
inlinestatic |
|
inline |
Get the log level for a certain module
[in] | module | PcapPlusPlus module |
void pcpp::Logger::internalPrintLogMessage | ( | std::ostringstream * | logStream, |
Logger::LogLevel | logLevel, | ||
const char * | file, | ||
const char * | method, | ||
int | line | ||
) |
An internal method to print log messages. Shouldn't be used externally.
|
inline |
Check whether a certain module is set to debug log level
[in] | module | PcapPlusPlus module |
|
static |
A static method for converting the log level enum to a string.
[in] | logLevel | A log level enum |
|
inline |
Get an indication if logs are currently enabled.
|
inline |
Set the log printer back to the default printer
|
inline |
Set all PcapPlusPlus modules to a certain log level
[in] | level | The log level to set all modules to |
Set the log level for a certain PcapPlusPlus module
[in] | module | PcapPlusPlus module |
[in] | level | The log level to set the module to |
|
inline |
Set a custom log printer.
[in] | printer | A log printer function that will be called for every log message |
|
inline |
Suppress logs in all PcapPlusPlus modules