-
Notifications
You must be signed in to change notification settings - Fork 3
Examples Collapse
Eduard Mishkurov edited this page Jun 11, 2026
·
4 revisions
This example shows how to collapse repeated log messages.
-
LogmeD_Collapse(...)/LogmeD_CollapseIgnore(...) -
LogmeI_Collapse(...)/LogmeI_CollapseIgnore(...) -
LogmeW_Collapse(...)/LogmeW_CollapseIgnore(...) -
LogmeE_Collapse(...)/LogmeE_CollapseIgnore(...) -
LogmeC_Collapse(...)/LogmeC_CollapseIgnore(...) -
LogmeD_CollapseEvery(...)/LogmeD_CollapseIgnoreEvery(...) -
LogmeI_CollapseEvery(...)/LogmeI_CollapseIgnoreEvery(...) -
LogmeW_CollapseEvery(...)/LogmeW_CollapseIgnoreEvery(...) -
LogmeE_CollapseEvery(...)/LogmeE_CollapseIgnoreEvery(...) -
LogmeC_CollapseEvery(...)/LogmeC_CollapseIgnoreEvery(...)
-
LogmeX_Collapse(limit, ...)uses the formatted message text as the repeat key. -
LogmeX_CollapseIgnore(ignoreRegex, limit, ...)removes all substrings matchingignoreRegexfrom the formatted message before comparing it with the previous message. -
LogmeX_CollapseEvery(intervalMs, ...)suppresses matching repeated messages until the interval expires. -
LogmeX_CollapseIgnoreEvery(ignoreRegex, intervalMs, ...)combines time-based collapse with ignored volatile substrings. -
LogmeX_CollapseIgnore(...)andLogmeX_CollapseIgnoreEvery(...)are intended for volatile fields such as request IDs, correlation IDs, timestamps, or counters. - Ignore variants print the original formatted message. The regular expression is used only for comparison.
-
Xis one of the usual log levels:D,I,W,E, orC. - The first message is printed immediately.
- Count-based collapse skips repeated messages from the same macro call site until the repeat counter reaches
limit. - Time-based collapse skips repeated messages from the same macro call site until
intervalMsexpires. - Other log messages written by other source lines do not reset that call site's counter.
- The example intentionally writes a normal
LogmeI(...)message between calls toLogmeW_Collapse(...)to show this behavior. - When the count limit is reached or the time interval expires, logme prints one message with the repeat counter and then starts counting again.
- logme does not currently print a final summary for pending suppressed repeats when the log is closed.
- Time-based collapse does not print a pending summary when the repeat key changes. The new key starts a new collapse series.
Collapse works on one formatted message at one macro call site. It does not automatically detect that several different log records form a repeated block.
For a repeated sequence such as MQTT Connecting, Connected, Subscribe, and Disconnected, either collapse each log statement separately, or write one diagnostic message containing embedded \n characters if the whole sequence should be treated as one block.
For messages with changing ids, use _CollapseIgnore or _CollapseIgnoreEvery to remove the volatile part from the comparison key:
LogmeI_CollapseIgnoreEvery(
R"(\[mqtt [0-9]+\])"
, 1000
, "[mqtt %llu] Connecting to MQTT broker"
, mqttId
);logme — flexible runtime logging system
Home · Getting Started · Architecture · Output · Backends · Configuration
GitHub: https://github.com/efmsoft/logme
- Home
- Getting Started
- Why logme?
- Core Concepts
- Logging Macros
- Fatal Handling
- Crash Logging
- glog Compatibility
- C API
- Choosing Logging Macros
- Function tracing
- Trace Points
- Override Scopes
- Advanced Features
- Collapse Logging
- Feature Map
- Overview
- Console Backend
- Debugger Backend
- File Backend
- File Rotation & Retention
- Buffer Backend
- Ring Buffer Backend
- SharedFile Backend
- Callback Backend
- Windows Event Log Backend
- Custom Backends
- Runtime Control
- Configuration
- Configuration JSON
- Control Server
- Environment Control
- Control Policies
- Trace Points
- Message Filtering