Loading
core: Add filtering capability to log outputs (fixes #83)
Resolves
Fixes #83
Description
This MR introduces string-based filtering for NS_LOG components. Users can now append a filter_<string> keyword to their environment variable configurations to selectively print logs that contain specific text (e.g., isolating logs by Node ID, time markers, or specific variable states).
Example Usage: NS_LOG="UdpEchoClientApplication=level_all|filter_sent" ./ns3 run first
Architecture & Performance
To ensure this feature introduces zero performance overhead when filtering is inactive, a fast-path/slow-path architecture was implemented inside log-macros-enabled.h:
- Fast Path: If
HasFilter()is false, the macro executes the original, unbufferedstd::clogstream injection. - Slow Path: If a filter is active, the macro evaluates the log expression into a
std::ostringstream, checks the resulting string against the filter, and flushes tostd::clogupon a match.
Testing
- Tested against standard examples (e.g.,
first.cc) to verify both unfiltered and filtered outputs function as expected. - Verified compilation under
debugprofile withNS3_ASSERTenabled.