Skip to content

Examples OneTime

Eduard Mishkurov edited this page May 13, 2026 · 7 revisions

OneTime example

OneTime

This example shows object-scoped one-time logging.

What it demonstrates

  • Deriving from OneTimeOverrideGenerator
  • Using LOGME_ONCE4THIS
  • Printing a message only once per object instance

Notes

  • This is useful for repetitive warnings that should appear once per object instead of once per call site.

Console output

2026-05-13 10:54:26:664 W Test::Method(): something went wrong!!!

Source code

Sources

Repository folder: examples/OneTime

OneTime.cpp

Open in repository

#include <Logme/Logme.h>

struct Test : Logme::OneTimeOverrideGenerator
{
  void Method()
  {
    // Even if this method is called many times, the message below will be printed only once for this object.
    LogmeW(LOGME_ONCE4THIS, "something went wrong!!!");
  }
};

int main()
{
  Test test;

  for (int i = 0; i < 1000; i++)
  {
    test.Method();
  }

  return 0;
}

Previous: OnceEvery | Next: Override

Clone this wiki locally