PcapPlusPlus  21.05
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) const
const LogLevelgetLogModulesArr () const
bool isErrorStringSet () const
char * getErrorString () const
void setErrorString (char *errString, int len)
int getErrorStringLength () const
void suppressErrors ()
void enableErrors ()
bool isSuppressErrors () const

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


Normal log level.


Debug log level.

Member Function Documentation

◆ enableErrors()

void pcpp::LoggerPP::enableErrors ( )

Enable all errors in all PcapPlusPlusModules

◆ getErrorString()

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

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

A pointer to the string

◆ getErrorStringLength()

int pcpp::LoggerPP::getErrorStringLength ( ) const

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

The user-defined error string length

◆ getInstance()

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

Get access to LoggerPP singleton

a pointer to the LoggerPP singleton

◆ getLogModulesArr()

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

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) ....

A pointer to the LogLevel array

◆ isDebugEnabled()

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

Check whether a certain module is set to debug log level

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

◆ isErrorStringSet()

bool pcpp::LoggerPP::isErrorStringSet ( ) const

Check whether error string was already set

true if error string was already set, false otherwise

◆ isSuppressErrors()

bool pcpp::LoggerPP::isSuppressErrors ( ) const

Get an indication if errors are currently suppressed

True if errors are currently suppressed, false otherwise

◆ setAllModlesToLogLevel()

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

Set all PcapPlusPlus modules to a certain log leve

[in]levelThe log level to set all modules to

◆ setErrorString()

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

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

[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 

Set the log level for a certain PcapPlusPlus module

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

◆ suppressErrors()

void pcpp::LoggerPP::suppressErrors ( )

Suppress all errors in all PcapPlusPlusModules