-
Notifications
You must be signed in to change notification settings - Fork 3
Examples Channels
Eduard Mishkurov edited this page May 3, 2026
·
7 revisions
This example shows how to work with multiple channels.
- Creating named channels
- Making a channel visible with a backend
- Making a channel visible by linking it to
::CH - Logging with either
Logme::IDorChannelPtr
- A custom channel does not produce visible output until it has backends or links.
- Passing
ChannelPtravoids channel name lookup.
2026-05-03 10:33:55:563 main(): Connected
2026-05-03 10:33:55:563 W main(): RTT=12 ms
2026-05-03 10:33:55:563 main(): Connected (ChannelPtr)
2026-05-03 10:33:55:563 W main(): RTT=12 ms (ChannelPtr)
2026-05-03 10:33:55:563 main(): Open file
2026-05-03 10:33:55:563 E Error: main(): Open failed: access denied
2026-05-03 10:33:55:563 main(): Button clicked
Repository folder: examples/Channels
#include <Logme/Logme.h>
#include <Logme/Backend/ConsoleBackend.h>
#include <memory>
#if defined(_MSC_VER)
#pragma warning(disable: 4840)
#endif
int main()
{
// NOTE:
// You can log to any channel ID, but to actually see output you must:
// 1) Create the channel (if it does not exist yet)
// 2) Add one or more backends, OR link it to another channel that has backends
//
// The default channel (::CH) is created automatically. It prints to console and, on Windows,
// also to the debugger output (OutputDebugStringA).
Logme::ID net{"net"};
Logme::ID fs{"fs"};
Logme::ID ui{"ui"};
// Option A: create a channel and attach a backend directly.
auto netCh = Logme::Instance->CreateChannel(net);
netCh->AddBackend(std::make_shared<Logme::ConsoleBackend>(netCh));
// Option B: link a channel to the default channel.
// A linked channel logs to its own backends first, then forwards to the linked channel.
auto fsCh = Logme::Instance->CreateChannel(fs);
fsCh->AddLink(::CH);
auto uiCh = Logme::Instance->CreateChannel(ui);
uiCh->AddLink(::CH);
// You can pass Channel ID...
LogmeI(net) << "Connected";
LogmeW(net, "RTT=%d ms", 12);
// ...or ChannelPtr (slightly faster, avoids name lookup).
LogmeI(netCh) << "Connected (ChannelPtr)";
LogmeW(netCh, "RTT=%d ms (ChannelPtr)", 12);
LogmeI(fs) << "Open file";
LogmeE(fs, "Open failed: %s", "access denied");
LogmeI(ui) << "Button clicked";
return 0;
}Previous: Basic | Next: ChannelSetup
logme — flexible runtime logging system
Home · Getting Started · Architecture · Output · Backends · Configuration
GitHub: https://github.com/efmsoft/logme
- Home
- Getting Started
- Why logme?
- Core Concepts
- Logging Macros
- Fatal Handling
- Crash Logging
- glog Compatibility
- C API
- Choosing Logging Macros
- Function tracing
- Trace Points
- Override Scopes
- Advanced Features
- Collapse Logging
- Feature Map
- Overview
- Console Backend
- Debugger Backend
- File Backend
- File Rotation & Retention
- Buffer Backend
- Ring Buffer Backend
- SharedFile Backend
- Callback Backend
- Windows Event Log Backend
- Custom Backends
- Runtime Control
- Configuration
- Configuration JSON
- Control Server
- Environment Control
- Control Policies
- Trace Points
- Message Filtering