Skip to content

Message Filtering

Eduard Mishkurov edited this page Jan 7, 2026 · 2 revisions

Message Filtering and Callbacks

logme supports fine-grained control over message emission.


Release Logging

By default, logging may be disabled in Release builds.

To force-enable logging in Release, define the macro:

  • LOGME_INRELEASE

When LOGME_INRELEASE is defined, logging calls remain active in Release builds and messages follow the same filtering and routing pipeline as in Debug.


Condition Callback (Global Filter)

logme provides a global condition callback that runs before any message processing. It can be installed via:

Logme::Instance->SetCondition(...);

Behavior:

  • The default condition always returns true.
  • The condition callback is evaluated before formatting and routing.
  • If the callback returns false, the message is discarded immediately.

Typical uses:

  • Temporarily muting all logging in the application
  • Suppressing logs for specific threads
  • Implementing dynamic runtime policies (e.g., based on environment or state)

Because the condition callback runs early, it is an efficient way to pause or block logging without changing channel configuration.


Override-Based Filtering (Rate / Count Limiting)

In addition to the global condition callback, logme supports dropping messages based on override rules.

Overrides can be used to:

  • Limit how often a message is allowed to appear (rate limiting)
  • Limit how many times a message is allowed to appear (count limiting)

If an override limit is exceeded, the message is discarded before formatting, routing, or delivery to any backend, including file backends.

Example: One-time message

The OneTime example demonstrates that even if the application attempts to log the same message 1000 times, it will appear only once when an override like LOGME_ONCE4THIS is used:

LogmeW(LOGME_ONCE4THIS, "something went wrong!!!");

Performance Notes

  • When logging is disabled at build time, the cost of logging calls (including filtering callbacks) is eliminated.
  • When enabled (including Release builds via LOGME_INRELEASE), the pipeline is designed to filter messages as early as possible to keep overhead low.

Clone this wiki locally