The log module provides a clean, stable, and high-level logging API for Vix applications.
It owns the canonical Vix logging implementation, exposing a consistent and developer-friendly interface while reusing a powerful logging backend.
Logging in Vix follows strict principles:
- No duplication of logging engines
- Simple public API (
vix::log) - Structured logging by default
- Explicit configuration
- Thread-local context support
- High performance (delegated to utils)
The module is designed to be:
- easy to use
- easy to integrate
- stable across versions
- consistent across all Vix modules
vix::log::Logger → logging engine
vix::log → public logging capability
The log module does not implement logging itself.
Historical vix::utils::Logger remains a temporary compatibility alias to
the canonical implementation.
#include <vix/log/Log.hpp> int main() { vix::log::info("Hello world"); vix::log::warn("Low disk space"); vix::log::error("Failed to open file"); }
vix::log::set_level(vix::log::LogLevel::Debug);Available levels:
- Trace
- Debug
- Info
- Warn
- Error
- Critical
- Off
vix::log::logf( vix::log::LogLevel::Info, "request completed", "status", 200, "method", "GET", "path", "/api/users" );
vix::log::set_format(vix::log::LogFormat::KV); vix::log::set_format(vix::log::LogFormat::JSON); vix::log::set_format(vix::log::LogFormat::JSON_PRETTY);
Attach metadata to all logs in a scope:
vix::log::LogContext ctx; ctx.request_id = "req-123"; ctx.module = "auth"; ctx.fields["user_id"] = "42"; vix::log::set_context(ctx); vix::log::info("user logged in"); vix::log::clear_context();
vix::log::LogConfig config; config.level = vix::log::LogLevel::Info; config.format = vix::log::LogFormat::JSON; config.async = true; vix::log::configure(config);
vix::log::set_level_from_env(); // VIX_LOG_LEVEL vix::log::set_format_from_env(); // VIX_LOG_FORMAT
Located in examples/:
- basic.cpp → basic logging
- context.cpp → context usage
- format.cpp → format switching
Located in test/:
- log_test.cpp
Run:
ctest
This module depends on:
vix::utils(logging backend)
No direct dependency on spdlog is exposed publicly.
- Simple API
- No duplication
- Structured logging first
- Context-aware
- High performance
- Stable interface
MIT Part of the Vix.cpp project.