Skip to content

Examples Basic

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

Basic example

Basic

This example shows the most basic logme usage.

What it demonstrates

  • Stream-style logging with LogmeI() << ...
  • Printf-style logging with LogmeI("...", ...)
  • Logging to a custom channel
  • Applying a local override to a single call
  • Using OBF(...) for an obfuscated string literal

Notes

  • The default channel ::CH is available automatically.
  • Custom channels must be made visible by linking them to ::CH or by attaching backends directly.

Console output

2026-05-13 10:54:20:192   BasicStream(): Hello from stream API
2026-05-13 10:54:20:192 W BasicStream(): 123
2026-05-13 10:54:20:192   BasicPrintf(): Hello World
2026-05-13 10:54:20:192 E Error: BasicPrintf(): Error code: -1
2026-05-13 10:54:20:192   ChannelAndOverride(): Channel stream
2026-05-13 10:54:20:192   ChannelAndOverride(): Channel printf: 42
2026-05-13 10:54:20:192   Override stream
2026-05-13 10:54:20:192   Override printf: ok
2026-05-13 10:54:20:192   ObfuscatedPrint(): This line cannot be found when viewing the exe

Source code

Sources

Repository folder: examples/Basic

Basic.cpp

Open in repository

#include <Logme/Logme.h>

static void BasicStream()
{
  LogmeI() << "Hello from stream API";
  LogmeW() << 123;
}

static void BasicPrintf()
{
  LogmeI("Hello %s", "World");
  LogmeE("Error code: %d", -1);
}

static void ChannelAndOverride()
{
  Logme::ID ch{"mychannel"};

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

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

  LogmeI(ch) << "Channel stream";
  LogmeI(ch, "Channel printf: %d", 42);

  LogmeI(ch, ovr) << "Override stream";
  LogmeI(ch, ovr, "Override printf: %s", "ok");
}

static void ObfuscatedPrint()
{
  LogmeI(OBF("This line cannot be found when viewing the exe"));
}

int main()
{
  BasicStream();
  BasicPrintf();
  ChannelAndOverride();
  ObfuscatedPrint();
  return 0;
}

Next: CApi

Clone this wiki locally