Skip to content

Examples FormatApi

Eduard Mishkurov edited this page Jun 10, 2026 · 7 revisions

FormatApi example

FormatApi

This example shows the supported formatting styles.

What it demonstrates

  • std::format-style logging when it is enabled
  • Fallback to stream / printf style when std::format support is disabled
  • Logging both to the default channel and to a custom channel

Notes

  • The fLogme... macros are available only when LOGME_DISABLE_STD_FORMAT is not defined.

Console output

2026-06-10 14:51:43:600   main(): Hello format, value=123
2026-06-10 14:51:43:600 W main(): Hex: 0xAB

Source code

Sources

Repository folder: examples/FormatApi

FormatApi.cpp

Open in repository

#include <Logme/Logme.h>

int main()
{
  Logme::ID ch{"fmt"};

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

#ifndef LOGME_DISABLE_STD_FORMAT
  fLogmeI("Hello {}, value={}", "format", 123);
  fLogmeW(ch, "Hex: 0x{:X}", 0xAB);
#else
  LogmeI() << "Hello " << "format" << ", value=" << 123;
  LogmeW(ch, "Hex: 0x%X", 0xAB);
#endif

  return 0;
}

Previous: EnvironmentControl | Next: Multithread

Clone this wiki locally