PcapPlusPlus
pcpp::LoggerPP Class Reference

#include <Logger.h>

Public Types

enum  LogLevel { Normal, Debug }
 

Public Member Functions

void setLogLevel (LogModule module, LogLevel level)
 
void setAllModlesToLogLevel (LogLevel level)
 
bool isDebugEnabled (LogModule module)
 
LogLevelgetLogModulesArr ()
 
bool isErrorStringSet ()
 
char * getErrorString ()
 
void setErrorString (char *errString, int len)
 
int getErrorStringLength ()
 
void supressErrors ()
 
void enableErrors ()
 
bool isSupressErrors ()
 

Static Public Member Functions

static LoggerPPgetInstance ()
 

Detailed Description

The PcapPlusPlus log manager class. PcapPlusPlus uses this logger to output both error and debug logs.

Debug logs: PcapPlusPlus is divided into modules (described in LogModule enum). The user can set each module or all modules to output or suppress debug messages. The default is suppressing debug messages. Changing debug log level for modules can be done dynamically while application is running.

Error logs: errors are printed by default to stderr. The user can change this behavior in several manners:

  1. Suppress errors - no errors will be printed (for all modules)
  2. Print error logs to a string provided by the user instead of stderr

PcapPlusPlus logger is a singleton which can be reached from anywhere in the code *

Member Enumeration Documentation

◆ LogLevel

An enum representing the log level. Currently 2 log level are supported: Normal and Debug. Normal is the default log level

Enumerator
Normal 

Normal log level.

Debug 

Debug log level.

Member Function Documentation

◆ enableErrors()

void pcpp::LoggerPP::enableErrors ( )
inline

Enable all errors in all PcapPlusPlusModules

◆ getErrorString()

char* pcpp::LoggerPP::getErrorString ( )
inline

Get the pointer to the error string set by the user. If no such pointer was provided by the user, NULL will be returned

Returns
A pointer to the string

◆ getErrorStringLength()

int pcpp::LoggerPP::getErrorStringLength ( )
inline

Get the user-defined error string length. If no such pointer was provided by the user, 0 will be returned

Returns
The user-defined error string length

◆ getInstance()

static LoggerPP& pcpp::LoggerPP::getInstance ( )
inlinestatic

Get access to LoggerPP singleton

Returns
a pointer to the LoggerPP singleton

◆ getLogModulesArr()

LogLevel* pcpp::LoggerPP::getLogModulesArr ( )
inline

Get an array that contains log level information for all modules. User can access this array with a certain PcapPlusPlus module and get the log level this module is currently in. For example: LogLevel* myLogLevelArr = getLogModulesArr(); if (myLogLevelArr[PacketLogModuleUdpLayer] == LogLevel::Debug) ....

Returns
A pointer to the LogLevel array

◆ isDebugEnabled()

bool pcpp::LoggerPP::isDebugEnabled ( LogModule  module)
inline

Check whether a certain module is set to debug log level

Parameters
[in]modulePcapPlusPlus module
Returns
True if this module log level is "debug". False otherwise

◆ isErrorStringSet()

bool pcpp::LoggerPP::isErrorStringSet ( )
inline

Check whether error string was already set

Returns
true if error string was already set, false otherwise

◆ isSupressErrors()

bool pcpp::LoggerPP::isSupressErrors ( )
inline

Get an indication if errors are currently suppressed

Returns
True if errors are currently suppressed, false otherwise

◆ setAllModlesToLogLevel()

void pcpp::LoggerPP::setAllModlesToLogLevel ( LogLevel  level)
inline

Set all PcapPlusPlus modules to a certain log leve

Parameters
[in]levelThe log level to set all modules to

◆ setErrorString()

void pcpp::LoggerPP::setErrorString ( char *  errString,
int  len 
)
inline

Set the error string to a string pointer provided by the user. By default all errors are printed to stderr. Using this method will cause PcapPlusPlus to output errors to the user string instead

Parameters
[in]errStringA string pointer provided by the user which all error messages will be print to from now on
[in]lenThe length of errString array. If

◆ setLogLevel()

void pcpp::LoggerPP::setLogLevel ( LogModule  module,
LogLevel  level 
)
inline

Set the log level for a certain PcapPlusPlus module

Parameters
[in]modulePcapPlusPlus module
[in]levelThe log level to set the module to

◆ supressErrors()

void pcpp::LoggerPP::supressErrors ( )
inline

Suppress all errors in all PcapPlusPlusModules