PcapPlusPlus icon indicating copy to clipboard operation
PcapPlusPlus copied to clipboard

Logger overhaul.

Open Dimi1010 opened this issue 1 year ago • 1 comments

Overhaul of the built-in logging infrastructure.

Removed exposed internals of Logger and added new log functions to serve as intermediaries. The new system is about as fast as the old one.

Benchmarking with 3000 error logs: Using dummy callback to eliminate variables from outputting to console:

void dummyCB(pcpp::Logger::LogLevel logLevel, const std::string& logMessage, const std::string& file, const std::string& method,
             const int line)
{
	volatile int x = 5;
}
  • 13ms~14ms in debug, both pre-change and post-change
  • 3ms~4ms in release, but I am unsure if that is because the logs were optimized away...

Changes:

  • Potentially Breaking Changed LogLevel to enum class and moved it to the pcpp namespace. Logger still retains aliases to the new enum. This can have potentially breaking effects if users used it to do arithmetic or something, but it should not be a big issue IMO.
  • Fixed wrong or missing LogModule values in the LoggingModule enum.
  • Removed exposed internals of the Logger class.
  • Added templated logging function log, logError, logInfo, logDebug to handle logging logic and encapsulate access to the logger internals.
  • Added new class LogSource to represent a file, function, lineNo and module in a single packaged format.
  • Standardized all PCPP_LOG_* macros to pass through PCPP_LOG.
  • Pulled ostream& operator<< pverloads for IPAddress and MacAddress inside pcpp to satisfy ADL.

Dimi1010 avatar Sep 30 '24 14:09 Dimi1010

Codecov Report

Attention: Patch coverage is 93.13305% with 16 lines in your changes missing coverage. Please review.

Project coverage is 83.12%. Comparing base (2d0fc5a) to head (8ac895d). Report is 1 commits behind head on dev.

Files with missing lines Patch % Lines
Common++/header/Logger.h 79.16% 9 Missing and 1 partial :warning:
Common++/src/Logger.cpp 84.84% 5 Missing :warning:
Pcap++/src/PcapLiveDeviceList.cpp 0.00% 1 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1596      +/-   ##
==========================================
+ Coverage   83.10%   83.12%   +0.01%     
==========================================
  Files         277      279       +2     
  Lines       48201    48395     +194     
  Branches     9955    10353     +398     
==========================================
+ Hits        40058    40228     +170     
+ Misses       7264     7034     -230     
- Partials      879     1133     +254     
Flag Coverage Δ
alpine320 75.09% <88.70%> (+0.01%) :arrow_up:
fedora40 75.15% <88.00%> (+0.03%) :arrow_up:
macos-13 80.61% <84.13%> (-0.01%) :arrow_down:
macos-14 80.60% <84.13%> (-0.02%) :arrow_down:
macos-15 80.58% <84.05%> (+<0.01%) :arrow_up:
mingw32 70.82% <76.00%> (-0.02%) :arrow_down:
mingw64 70.76% <76.00%> (-0.06%) :arrow_down:
npcap 85.21% <83.59%> (-0.04%) :arrow_down:
rhel94 75.01% <88.80%> (+0.04%) :arrow_up:
ubuntu2004 58.59% <82.45%> (+0.04%) :arrow_up:
ubuntu2004-zstd 58.71% <82.45%> (+0.03%) :arrow_up:
ubuntu2204 74.92% <88.80%> (+0.03%) :arrow_up:
ubuntu2204-icpx 61.27% <67.42%> (-0.18%) :arrow_down:
ubuntu2404 75.16% <88.70%> (+0.01%) :arrow_up:
unittest 83.12% <93.13%> (+0.01%) :arrow_up:
windows-2019 85.24% <83.59%> (-0.04%) :arrow_down:
windows-2022 85.27% <83.46%> (-0.04%) :arrow_down:
winpcap 85.24% <83.59%> (-0.03%) :arrow_down:
xdp 50.41% <23.18%> (-0.13%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Sep 30 '24 15:09 codecov[bot]

@Dimi1010 can you address the remaining comments so we can merge this PR?

seladb avatar Dec 24 '24 20:12 seladb