-
Notifications
You must be signed in to change notification settings - Fork 3
Examples Collapse
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(...)
-
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_CollapseIgnore(...)is intended for volatile fields such as request IDs, correlation IDs, timestamps, or counters. -
LogmeX_CollapseIgnore(...)prints 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.
- Repeated messages from the same macro call site are skipped until the repeat counter reaches
limit. - 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 limit is reached, logme prints one message with the repeat counter and then starts counting again.
- The limit is count-based, not time-based.
- logme does not currently print a final summary for pending suppressed repeats when the log is closed.
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 to remove the volatile part from the comparison key:
LogmeI_CollapseIgnore(
R"(\[mqtt [0-9]+\])"
, 20
, "[mqtt %llu] Connecting to MQTT broker"
, mqttId
);2026-06-10 14:51:40:170 W SameText(): network error: connection refused
2026-06-10 14:51:40:170 SameText(): retry loop is still active, attempt 0
2026-06-10 14:51:40:170 SameText(): retry loop is still active, attempt 1
2026-06-10 14:51:40:170 SameText(): retry loop is still active, attempt 2
2026-06-10 14:51:40:170 W SameText(): repeated 3 times: network error: connection refused
2026-06-10 14:51:40:170 SameText(): retry loop is still active, attempt 3
2026-06-10 14:51:40:170 E Error: IgnoreCorrelationId(): request failed: correlation-id=0, network error: connection refused
2026-06-10 14:51:40:170 E Error: IgnoreCorrelationId(): repeated 2 times: request failed: correlation-id=2, network error: connection refused
Repository folder: examples/Collapse
#include <Logme/Logme.h>
static void SameText()
{
for (int i = 0; i < 4; i++)
{
LogmeW_Collapse(3, "network error: connection refused");
LogmeI("retry loop is still active, attempt %d", i);
}
}
static void IgnoreCorrelationId()
{
for (int i = 0; i < 3; i++)
{
LogmeE_CollapseIgnore(
"correlation-id=[0-9]+"
, 2
, "request failed: correlation-id=%d, network error: connection refused"
, i
);
}
}
int main()
{
SameText();
IgnoreCorrelationId();
return 0;
}Previous: ChannelSetup | Next: DumpBuffer
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