Skip to content

Examples Override

Eduard Mishkurov edited this page Apr 24, 2026 · 7 revisions

Override example

Override

This example shows how local overrides modify a log record.

What it demonstrates

  • Creating a Logme::Override
  • Removing the method name from output
  • Using overrides with the default channel and a custom channel
  • Stream-style and printf-style calls with the same override

Notes

  • Overrides can be applied per call without changing global logger configuration.

Console output

2026-04-24 21:26:29:360   DefaultBehavior(): Default output
2026-04-24 21:26:29:360   Method removed (stream)
2026-04-24 21:26:29:360   Method removed (printf): 7
2026-04-24 21:26:29:360 W Warning with override
2026-04-24 21:26:29:360 E Error: Error with override: fail

Source code

Sources

Repository folder: examples/Override

Override.cpp

Open in repository

#include <Logme/Logme.h>

static void DefaultBehavior()
{
  LogmeI() << "Default output";
}

static void WithoutMethod()
{
  Logme::Override ovr;
  ovr.Remove.Method = true;

  LogmeI(ovr) << "Method removed (stream)";
  LogmeI(ovr, "Method removed (printf): %d", 7);
}

static void WithChannelAndOverride()
{
  Logme::ID ch{"custom"};

  auto channel = Logme::Instance->CreateChannel(ch);
  channel->AddLink(::CH);

  Logme::Override ovr;
  ovr.Remove.Method = true;

  LogmeW(ch, ovr) << "Warning with override";
  LogmeE(ch, ovr, "Error with override: %s", "fail");
}

int main()
{
  DefaultBehavior();
  WithoutMethod();
  WithChannelAndOverride();
  return 0;
}

Previous: OneTime | Next: Precheck

Clone this wiki locally