-
Notifications
You must be signed in to change notification settings - Fork 2
FAQ
First, make sure that your code is not explicitly logging the same message multiple times.
If this is not the case, the most common reason is channel linking combined with shared backends.
If a channel is linked to another channel, and both channels have the same backend
(for example ConsoleBackend), the message will be routed through both paths and printed
multiple times.
Example:
Logme::ID chId{"test"};
auto ch = Logme::Instance->CreateChannel(chId);
ch->AddBackend(std::make_shared<Logme::ConsoleBackend>(ch));
ch->AddLink(::CH); // the default channel usually already has ConsoleBackend
LogmeI(ch, "duplicated message");In this example:
-
chhas its ownConsoleBackend -
chis linked to the default channelCH -
CHalso has aConsoleBackend
As a result, the message is printed twice.
How to fix
- Avoid attaching the same backend to both a channel and its linked parent
- Or rely on routing via links without duplicating backends
There are several common reasons why log messages may not appear.
By default, logging may be disabled in Release builds to eliminate runtime overhead.
If logging is required in Release builds, the application must be built with the
LOGME_INRELEASE macro enabled.
In Logme it is valid to log to a channel by ID without creating it first.
This is intentional: subsystems may log to their own named channels, and those channels
can be created and configured later, when there is interest in their output.
Logme::ID ch{"some_name"};
LogmeI(ch, "hello"); // valid, but produces no output if the channel is not routedHowever, a channel that is not routed to any backend (directly or via links) will not produce any output, so messages will be dropped.
To make messages visible, create and configure the channel:
auto ch = Logme::Instance->CreateChannel(ch);
ch->AddBackend(std::make_shared<Logme::ConsoleBackend>(ch));
LogmeI(ch, "hello2"); // now visibleAlternatively, link the channel to another channel that already has backends:
auto ch = Logme::Instance->CreateChannel("some_name");
ch->AddLink(::CH);Each channel has a log level filter.
By default, CreateChannel() sets the level to LEVEL_INFO.
LogmeD(ch, "hello3"); // dropped because LEVEL_DEBUG < LEVEL_INFOLower the channel log level if needed:
ch->SetLevel(Logme::Level::LEVEL_DEBUG);A disabled channel drops all messages unconditionally:
ch->SetEnabled(false);
LogmeI(ch, "hello4"); // droppedFormatting issues are usually caused by mixing incompatible formatting styles.
Logme provides two distinct macro families, each using its own formatting mechanism.
These macros use C++20-style formatting (std::format-like syntax):
LogmeI("value={}", 1); // correctUsing C-style format specifiers will not work:
LogmeI("value=%i", 1); // prints: value=%iThese macros expect classic C-style formatting:
fLogmeI("value=%i", 1); // correctUsing {} placeholders here will not work:
fLogmeI("value={}", 1); // prints: value={}| Macro family | Formatting style |
|---|---|
LogmeI, LogmeE, ... |
{} (C++20 / std::format style) |
fLogmeI, fLogmeE, ... |
% (C-style formatting) |
Attaching the same type of backend (for example ConsoleBackend) to both a channel
and its linked parent channel often results in duplicated output.
Recommendation
Attach backends at a single routing level and use channel links only for propagation.
Logging to a channel ID without routing it anywhere is valid, but often misunderstood. Messages will remain invisible until the channel is routed to a backend.
LogmeI("net", "connection opened"); // valid, but invisible without routingRecommendation
- Route channels explicitly when their output is needed
- Use dynamic channel creation to enable logging on demand
The default channel level is LEVEL_INFO.
Debug messages will not be visible unless the level is lowered explicitly.
Recommendation
- Set channel levels explicitly in configuration code or JSON
- Avoid relying on implicit defaults
Using {} placeholders with fLogme* macros or % specifiers with Logme* macros
will always result in unformatted output.
Recommendation
- Use
Logme*macros for modern C++20-style formatting - Use
fLogme*macros only when C-style formatting is required
Release builds may completely remove logging code.
Recommendation
- Enable
LOGME_INRELEASEif logging is required - Document this requirement clearly in build instructions
logme — flexible runtime logging system
Home · Getting Started · Architecture · Output · Backends · Configuration
GitHub: https://github.com/efmsoft/logme