Skip to content

Examples ChannelSetup

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

ChannelSetup example

ChannelSetup

This example shows how channel visibility is configured.

What it demonstrates

  • Logging to a channel before it is configured
  • Creating a channel explicitly
  • Making it visible with AddLink(::CH)
  • The simplest pattern for custom channels

Notes

  • Creating a channel alone is not enough to see output.
  • Linking to ::CH is the easiest way to reuse the default backend configuration.

Console output

2026-06-10 14:51:40:086   main(): Now visible via AddLink(::CH)

Source code

Sources

Repository folder: examples/ChannelSetup

ChannelSetup.cpp

Open in repository

#include <Logme/Logme.h>

#include <chrono>
#include <thread>

int main()
{
  Logme::ID id{"invisible"};

  // This is allowed, but you may not see any output if the channel is not created
  // and does not have any backends or links.
  LogmeI(id, "This may be invisible (channel has no backends/links yet)");

  // Create the channel explicitly.
  auto ch = Logme::Instance->CreateChannel(id);

  // Option A: link to the default channel (::CH) which already has backends.
  // This is the simplest way to make a custom channel visible.
  ch->AddLink(::CH);

  LogmeI(id, "Now visible via AddLink(::CH)");

  // Option B: add a backend directly (example: console backend).
  // If you prefer this approach, keep AddLink() disabled to avoid duplicate output.
  //
  // ch->AddBackend(std::make_shared<ConsoleBackend>(ch));

  // Small delay so the user can see output in quick runs.
  std::this_thread::sleep_for(std::chrono::milliseconds(10));
  return 0;
}

Previous: Channels | Next: Collapse

Clone this wiki locally