PcapPlusPlus  19.12
Logger.h
Go to the documentation of this file.
1 #ifndef PCAPPP_LOGGER
2 #define PCAPPP_LOGGER
3 
4 #include <stdio.h>
5 #include <stdint.h>
6 
7 #ifndef LOG_MODULE
8 #define LOG_MODULE UndefinedLogModule
9 #endif
10 
12 
17 namespace pcpp
18 {
19 
23  enum LogModule
24  {
25  UndefinedLogModule,
65  NumOfLogModules
66  };
67 
82  class LoggerPP
83  {
84  public:
88  enum LogLevel
89  {
92  };
93 
99  void setLogLevel(LogModule module, LogLevel level) { m_LogModulesArray[module] = level; }
100 
105  void setAllModlesToLogLevel(LogLevel level) { for (int i=1; i<NumOfLogModules; i++) m_LogModulesArray[i] = level; }
106 
112  bool isDebugEnabled(LogModule module) const { return m_LogModulesArray[module] == Debug; }
113 
121  const LogLevel* getLogModulesArr() const { return m_LogModulesArray; }
122 
127  bool isErrorStringSet() const { return m_ErrorString != NULL; }
128 
133  char* getErrorString() const { return m_ErrorString; }
134 
141  void setErrorString(char* errString, int len) { m_ErrorString = errString; m_ErrorStringLen = len; }
142 
147  int getErrorStringLength() const { return m_ErrorStringLen; }
148 
152  void supressErrors() { m_SuppressErrors = true; }
153 
157  void enableErrors() { m_SuppressErrors = false; }
158 
163  bool isSupressErrors() const { return m_SuppressErrors; }
164 
171  {
172  static LoggerPP instance;
173  return instance;
174  }
175  private:
176  char* m_ErrorString;
177  int m_ErrorStringLen;
178  bool m_SuppressErrors;
179  LoggerPP::LogLevel m_LogModulesArray[NumOfLogModules];
180  LoggerPP();
181  };
182 
183 #define LOG_DEBUG(format, ...) do { \
184  if(pcpp::LoggerPP::getInstance().isDebugEnabled(LOG_MODULE)) { \
185  printf("[%-35s: %-25s: line:%-4d] " format "\n", __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
186  } \
187  } while(0)
188 
189 #define LOG_ERROR(format, ...) do { \
190  if (!pcpp::LoggerPP::getInstance().isSupressErrors()) {\
191  if(pcpp::LoggerPP::getInstance().isErrorStringSet()) \
192  snprintf(pcpp::LoggerPP::getInstance().getErrorString(), pcpp::LoggerPP::getInstance().getErrorStringLength(), format "\n", ## __VA_ARGS__); \
193  else \
194  fprintf(stderr, format "\n", ## __VA_ARGS__); \
195  } \
196  } while (0)
197 
198 #define IS_DEBUG pcpp::LoggerPP::getInstance().isDebugEnabled(LOG_MODULE)
199 
200 } // namespace pcpp
201 
202 #endif /* PCAPPP_LOGGER */
pcpp::PacketLogModuleDhcpLayer
DhcpLayer module (Packet++)
Definition: Logger.h:48
pcpp::PcapLogModulePfRingDevice
PfRingDevice module (Pcap++)
Definition: Logger.h:60
pcpp::PacketLogModuleIPv6Layer
IPv6Layer module (Packet++)
Definition: Logger.h:35
pcpp::PacketLogModuleSdpLayer
SdpLayer module (Packet++)
Definition: Logger.h:51
pcpp::PacketLogModuleSllLayer
SllLayer module (Packet++)
Definition: Logger.h:47
pcpp::PacketLogModulePacket
Packet module (Packet++)
Definition: Logger.h:30
pcpp::PacketLogModuleRadiusLayer
RadiusLayer module (Packet++)
Definition: Logger.h:52
pcpp::LoggerPP::enableErrors
void enableErrors()
Definition: Logger.h:157
pcpp::PacketLogModulePayloadLayer
PayloadLayer module (Packet++)
Definition: Logger.h:36
pcpp::LoggerPP::setErrorString
void setErrorString(char *errString, int len)
Definition: Logger.h:141
pcpp::PacketLogModuleVlanLayer
VlanLayer module (Packet++)
Definition: Logger.h:39
pcpp::LogModule
LogModule
Definition: Logger.h:23
pcpp::LoggerPP::isDebugEnabled
bool isDebugEnabled(LogModule module) const
Definition: Logger.h:112
pcpp::PcapLogModuleMBufRawPacket
MBufRawPacket module (Pcap++)
Definition: Logger.h:61
pcpp::LoggerPP::Debug
Debug log level.
Definition: Logger.h:91
pcpp::LoggerPP::getInstance
static LoggerPP & getInstance()
Definition: Logger.h:170
pcpp::CommonLogModuleIpUtils
IP Utils module (Common++)
Definition: Logger.h:26
pcpp::LoggerPP::getErrorString
char * getErrorString() const
Definition: Logger.h:133
pcpp::PacketLogModuleIPReassembly
IPReassembly module (Packet++)
Definition: Logger.h:55
pcpp::LoggerPP::setAllModlesToLogLevel
void setAllModlesToLogLevel(LogLevel level)
Definition: Logger.h:105
pcpp::LoggerPP::Normal
Normal log level.
Definition: Logger.h:90
pcpp::PacketLogModuleIgmpLayer
IgmpLayer module (Packet++)
Definition: Logger.h:49
pcpp::PacketLogModuleHttpLayer
HttpLayer module (Packet++)
Definition: Logger.h:40
pcpp::LoggerPP
Definition: Logger.h:82
pcpp::LoggerPP::isErrorStringSet
bool isErrorStringSet() const
Definition: Logger.h:127
pcpp::PacketLogModuleSipLayer
SipLayer module (Packet++)
Definition: Logger.h:50
pcpp::PcapLogModuleLiveDevice
PcapLiveDevice module (Pcap++)
Definition: Logger.h:58
pcpp::PacketLogModuleGtpLayer
GtpLayer module (Packet++)
Definition: Logger.h:53
pcpp::PacketLogModuleDnsLayer
DnsLayer module (Packet++)
Definition: Logger.h:42
pcpp::PacketLogModuleRawPacket
RawPacket module (Packet++)
Definition: Logger.h:29
pcpp::PacketLogModuleMplsLayer
MplsLayer module (Packet++)
Definition: Logger.h:43
pcpp::PacketLogModuleIPv4Layer
IPv4Layer module (Packet++)
Definition: Logger.h:34
pcpp::PcapLogModuleFileDevice
FileDevice module (Pcap++)
Definition: Logger.h:59
pcpp::PcapLogModuleDpdkDevice
DpdkDevice module (Pcap++)
Definition: Logger.h:62
pcpp::CommonLogModuleGenericUtils
Generic Utils (Common++)
Definition: Logger.h:28
pcpp
The main namespace for the PcapPlusPlus lib.
pcpp::NetworkUtils
NetworkUtils module (Pcap++)
Definition: Logger.h:64
pcpp::LoggerPP::getErrorStringLength
int getErrorStringLength() const
Definition: Logger.h:147
pcpp::PacketLogModuleSSLLayer
SSLLayer module (Packet++)
Definition: Logger.h:46
pcpp::LoggerPP::getLogModulesArr
const LogLevel * getLogModulesArr() const
Definition: Logger.h:121
pcpp::PcapLogModuleKniDevice
KniDevice module (Pcap++)
Definition: Logger.h:63
pcpp::PacketLogModuleGreLayer
GreLayer module (Packet++)
Definition: Logger.h:45
pcpp::PcapLogModuleRemoteDevice
WinPcapRemoteDevice module (Pcap++)
Definition: Logger.h:57
pcpp::LoggerPP::LogLevel
LogLevel
Definition: Logger.h:88
pcpp::PacketLogModuleTcpLayer
TcpLayer module (Packet++)
Definition: Logger.h:37
pcpp::LoggerPP::setLogLevel
void setLogLevel(LogModule module, LogLevel level)
Definition: Logger.h:99
pcpp::PcapLogModuleWinPcapLiveDevice
WinPcapLiveDevice module (Pcap++)
Definition: Logger.h:56
pcpp::PacketLogModuleUdpLayer
UdpLayer module (Packet++)
Definition: Logger.h:38
pcpp::PacketLogModuleTcpReassembly
TcpReassembly module (Packet++)
Definition: Logger.h:54
pcpp::PacketLogModuleLayer
Layer module (Packet++)
Definition: Logger.h:31
pcpp::PacketLogModulePPPoELayer
PPPoELayer module (Packet++)
Definition: Logger.h:41
pcpp::LoggerPP::supressErrors
void supressErrors()
Definition: Logger.h:152
pcpp::PacketLogModuleArpLayer
ArpLayer module (Packet++)
Definition: Logger.h:32
pcpp::PacketLogModuleEthLayer
EthLayer module (Packet++)
Definition: Logger.h:33
pcpp::LoggerPP::isSupressErrors
bool isSupressErrors() const
Definition: Logger.h:163
pcpp::CommonLogModuleTablePrinter
Table printer module (Common++)
Definition: Logger.h:27
pcpp::PacketLogModuleIcmpLayer
IcmpLayer module (Packet++)
Definition: Logger.h:44