Appearance
Logging
The framework includes a built-in logging system with scope-based filtering. Logging is done via macros that respect the configured scopes.
Basic Usage
cpp
#include <framework/support/logging.hpp>
// Log with scope checking (requires config reference)
LOG_INFO_SVC(config, "Server started on port {}", 8080);
LOG_WARN_SVC(config, "Connection timeout from {}", client_ip);
LOG_ERROR_SVC(config, "Failed to process request: {}", error_message);
LOG_INFO_OP(config, "Operational event: cache hit for key {}", key);
LOG_WARN_OP(config, "Operational warning");
LOG_ERROR_OP(config, "Operational error");
// Log without scope checking (unconditional, but still gated by ENABLE_SILENCE)
LOG_INFO_SVC_NO_CONFIG("Server started");
LOG_WARN_SVC_NO_CONFIG("Warning message");
LOG_ERROR_SVC_NO_CONFIG("Error message");
// Implementation layer (internal details)
LOG_INFO_IMPL("Cache miss for key {}", key);
LOG_DEBUG_IMPL("Vector clock: {}", clock_value);
// Raw output (no tags, plain spdlog)
LOG_RAW_INFO("Plain info message");
LOG_RAW_ERROR("Plain error message");
LOG_RAW_OUT(some_variable); // std::cout << some_variable << std::endl
LOG_RAW_ERR(some_variable); // std::cerr << some_variable << std::endlLog Scopes
| Layer | Macros | Description |
|---|---|---|
service | LOG_INFO_SVC, LOG_WARN_SVC, LOG_ERROR_SVC | Normal service messages (tagged [svc]) |
operational | LOG_INFO_OP, LOG_WARN_OP, LOG_ERROR_OP | Important operational events (tagged [op]) |
implementation | LOG_INFO_IMPL, LOG_WARN_IMPL, LOG_ERROR_IMPL, LOG_DEBUG_IMPL | Internal details (tagged [impl]) |
Configuration
Logging scopes are configured through the configuration object:
cpp
config.logging_.scope_bitset_.store(3); // service | operational
config.logging_.scopes_.store(
std::make_shared<const std::vector<std::string>>(
std::vector<std::string>{"service", "operational"}
)
);The scope bitset controls which scopes produce output:
- Bit 0: service
- Bit 1: operational
- Bit 2: verbose
Both the bitset and the scopes array control the same setting — they are equivalent. The scopes array is converted to a bitset internally via sync_log_bitset(). Use whichever is more convenient for your configuration format.
Silence Mode
Define ENABLE_SILENCE at compile time to disable all logging:
bash
cmake .. -DENABLE_SILENCE=ONWhen enabled, all log macros expand to no-ops.