PcapPlusPlus
Next
|
#include <Logger.h>
Public Types | |
using | LogPrinter = std::add_pointer< void(LogLevel logLevel, const std::string &logMessage, const std::string &file, const std::string &method, const int line)>::type |
Public Member Functions | |
LogLevel | getLogLevel (LogModule module) |
void | setLogLevel (LogModule module, LogLevel level) |
bool | isDebugEnabled (LogModule module) const |
bool | shouldLog (LogLevel level, LogModule module) const |
Check whether a log level should be emitted by the logger. More... | |
void | setAllModulesToLogLevel (LogLevel level) |
void | setLogPrinter (LogPrinter printer) |
void | resetLogPrinter () |
Set the log printer back to the default printer. | |
std::string | getLastError () const |
void | suppressLogs () |
Suppress logs in all PcapPlusPlus modules. | |
void | enableLogs () |
Enable logs in all PcapPlusPlus modules. | |
bool | logsEnabled () const |
void | useContextPooling (bool enabled, std::size_t preallocate=2, std::size_t maxPoolSize=10) |
Controls if the logger should use a pool of LogContext objects. More... | |
std::unique_ptr< internal::LogContext > | createLogContext () |
Creates a new LogContext with Info level and no source. More... | |
std::unique_ptr< internal::LogContext > | createLogContext (LogLevel level, LogSource const &source={}) |
Creates a new LogContext with the given level and source. More... | |
void | emit (LogSource const &source, LogLevel level, std::string const &message) |
Directly emits a log message bypassing all level checks. More... | |
void | emit (std::unique_ptr< internal::LogContext > message) |
Directly emits a log message bypassing all level checks. More... | |
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.
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 |
std::unique_ptr<internal::LogContext> pcpp::Logger::createLogContext | ( | ) |
Creates a new LogContext with Info level and no source.
std::unique_ptr<internal::LogContext> pcpp::Logger::createLogContext | ( | LogLevel | level, |
LogSource const & | source = {} |
||
) |
Creates a new LogContext with the given level and source.
level | The log level for this message. |
source | The log source. |
Directly emits a log message bypassing all level checks.
source | The log source. |
level | The log level for this message. This is only used for the log printer. |
message | The log message. |
void pcpp::Logger::emit | ( | std::unique_ptr< internal::LogContext > | message | ) |
Directly emits a log message bypassing all level checks.
message | The log message. |
|
inlinestatic |
|
inline |
Get the log level for a certain module
[in] | module | PcapPlusPlus module |
|
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 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 |
Check whether a log level should be emitted by the logger.
level | The level of the log message. |
module | PcapPlusPlus module |
|
inline |
Controls if the logger should use a pool of LogContext objects.
If enabled is set to false, preallocate and maxPoolSize are ignored.
enabled | True to enable context pooling, false to disable. |
preallocate | The number of LogContext objects to preallocate in the pool. |
maxPoolSize | The maximum number of LogContext objects to keep in the pool. |