Debug Quick Start
This page shows the fastest way to use rix/debug.
The examples use the public Rix facade:
#include <rix.hpp>and access Debug through:
rix.debugrix/debug is useful for examples, quick tools, local diagnostics, and development-time output.
For production application logs, prefer the Vix logging system.
What you will build
You will create a small C++ file that:
prints values
prints an error message
formats a string
stores printed output in a string
inspects a value
runs with vix runCreate a working folder
Create a small folder in your home directory:
mkdir -p ~/rix-debug-quick-start
cd ~/rix-debug-quick-start
touch debug.cppAdd the example
Open:
debug.cppAdd:
#include <rix.hpp>
#include <string>
int main()
{
rix.debug.print("== rix/debug quick start ==");
rix.debug.print("Hello", "Rix");
rix.debug.print("rows:", 3);
rix.debug.print("ready:", true);
const std::string package =
rix.debug.format("Package: {}", "rix/debug");
rix.debug.print(package);
const std::string line =
rix.debug.sprint("generated line:", package);
rix.debug.print(line);
rix.debug.eprint("stderr example:", "this is an error-style message");
rix.debug.inspect(package);
return 0;
}Run the file
Run:
vix run debug.cppIf Rix is not available yet for single-file usage:
vix install -g rix/rix
vix run debug.cppExpected output
The output should look similar to this:
== rix/debug quick start ==
Hello Rix
rows: 3
ready: true
Package: rix/debug
generated line: Package: rix/debugThe eprint output is written to stderr.
The exact inspect output depends on the inspected value.
Print values
Use:
rix.debug.print(...)Example:
rix.debug.print("Hello", "Rix");
rix.debug.print("count:", 3);
rix.debug.print("ok:", true);print writes values separated by spaces and adds a newline.
This is the most common rix/debug helper.
Print errors
Use:
rix.debug.eprint(...)Example:
rix.debug.eprint("error:", "something failed");eprint writes to stderr.
Use it for examples, local diagnostics, and command-line tools.
Debug-only print
Use:
rix.debug.dprint(...)Example:
rix.debug.dprint("debug value:", 42);Use this when the message is only useful while debugging.
Format a string
Use:
rix.debug.format(...)Example:
const auto message =
rix.debug.format("Package: {}", "rix/debug");
rix.debug.print(message);Output:
Package: rix/debugAutomatic placeholders
Use {} to insert arguments in order:
const auto message =
rix.debug.format("{} uses {}", "Rix", "C++");Result:
Rix uses C++Explicit placeholders
Use {0}, {1}, and other indexes when you want explicit argument positions:
const auto message =
rix.debug.format("{0} + {0} = {1}", "C++", "Vix.cpp");Result:
C++ + C++ = Vix.cppDo not mix automatic placeholders and explicit placeholders in the same format string.
Escape braces
Use double opening braces and double closing braces when you need literal braces:
const auto message =
rix.debug.format("{{ package }} = {}", "rix/debug");Result:
{ package } = rix/debugUnsupported format specifiers
rix.debug.format is intentionally small.
It does not support format specifiers such as:
{:.2f}
{:>10}
{:04d}Use simple placeholders.
For advanced formatting, use another formatting library or normal C++ formatting tools where appropriate.
Append formatted output
You can append formatted text to an existing string:
std::string out = "Rix: ";
rix.debug.format.append(
out,
"{}",
"debug");
rix.debug.print(out);Expected output:
Rix: debugReplace a string with formatted output
Use:
std::string out;
rix.debug.format.to(
out,
"Package: {}",
"rix/debug");
rix.debug.print(out);Expected output:
Package: rix/debugSprint values into a string
Use:
rix.debug.sprint(...)when you want the same value rendering as print, but returned as a string.
Example:
const auto line =
rix.debug.sprint("rows:", 3);
rix.debug.print(line);This is useful when you want to build a message before printing it.
Inspect a value
Use:
rix.debug.inspect(value);Example:
std::string package = "rix/debug";
rix.debug.inspect(package);Inspection is useful when you want a clearer development-time view of a value.
Complete formatting example
#include <rix.hpp>
#include <string>
int main()
{
const auto one =
rix.debug.format("Hello, {}", "Ada");
const auto two =
rix.debug.format("{0} builds on {1}", "Rix", "Vix.cpp");
const auto three =
rix.debug.format("{{ module }} = {}", "debug");
rix.debug.print(one);
rix.debug.print(two);
rix.debug.print(three);
return 0;
}Run:
vix run debug.cppExpected output:
Hello, Ada
Rix builds on Vix.cpp
{ module } = debugUse in a Vix project
Create a Vix application:
vix new debug-app --app
cd debug-appAdd Rix:
vix add rix/rix
vix installIn vix.app, make sure Rix is listed under deps:
deps = [
"rix/rix",
]A small vix.app can look like this:
name = "debug-app"
type = "executable"
standard = "c++20"
output_dir = "bin"
sources = [
"src/main.cpp",
]
include_dirs = [
"include",
"src",
]
deps = [
"rix/rix",
]
packages = [
"vix",
]
links = [
"vix::vix",
]Then use Debug in src/main.cpp:
#include <rix.hpp>
int main()
{
rix.debug.print("Hello", "Rix");
const auto message =
rix.debug.format("Package: {}", "rix/debug");
rix.debug.print(message);
return 0;
}Build and run:
vix build
vix runSingle-file usage
For small scripts, examples, and experiments, use:
vix run debug.cppIf Rix is installed globally for single-file usage:
vix install -g rix/rix
vix run debug.cppFor project usage, prefer:
vix add rix/rix
vix installand keep the dependency in vix.app:
deps = [
"rix/rix",
]Use only Debug with the facade
If you want the rix.* facade style but only want Debug mounted, define the feature macro before including rix.hpp:
#define RIX_ENABLE_DEBUG
#include <rix.hpp>
int main()
{
rix.debug.print("Hello", "Rix");
return 0;
}When at least one RIX_ENABLE_* macro is defined, only selected modules are mounted.
This is useful for lighter builds.
Use the independent package
For independent usage, install:
vix add rix/debug
vix installIn vix.app:
deps = [
"rix/debug",
]Then include the independent package header:
#include <rix/debug.hpp>Use this style when a project only needs Debug and does not need the full unified Rix facade.
For most application documentation, prefer:
#include <rix.hpp>Debug with CSV
Debug is useful for printing parsed CSV data:
const auto table = rix.csv.parse(
"name,language\n"
"Ada,C++\n");
rix.debug.print("rows:", table.size());
for (const auto &row : table)
{
rix.debug.print("fields:", row.size());
}Debug with Auth
Debug is useful for examples that show Auth results:
auto auth = rix.auth.memory();
auto registered = auth.register_user({
"ada@example.com",
"correct-password"});
if (registered.failed())
{
const auto &error = registered.error();
rix.debug.eprint(
"auth error:",
rix.auth.error.to_string(error),
error.message());
return 1;
}
rix.debug.print("registered:", registered.value().email());Do not print authentication secrets in production.
Avoid printing:
plain-text passwords
password hashes
session ids
raw token valuesDebug with PDF
Debug is useful for checking whether a PDF was created:
auto doc = rix.pdf.document();
auto &page = doc.add_page();
page.text(
page.x_left(),
page.y_top(),
"Hello from rix.pdf");
auto saved = rix.pdf.save(doc, "example.pdf");
if (saved.failed())
{
rix.debug.eprint(
"pdf error:",
rix.pdf.error.to_string(saved.error()),
saved.error().message());
return 1;
}
rix.debug.print("created:", "example.pdf");Logging note
rix/debug is not the main production logging API.
Use rix.debug.print, rix.debug.eprint, rix.debug.dprint, rix.debug.format, and rix.debug.inspect for development output and documentation examples.
For real application logs, prefer the Vix logging system.
Use this rule:
rix.debug -> examples, local diagnostics, quick tools
Vix logging -> production logs, service logs, request logsCommon mistakes
Using debug output as production logging
rix.debug is for simple development output.
For real application logs, use the Vix logging system.
Printing secrets
Do not print:
plain-text passwords
password hashes
session ids
raw token valuesThis matters especially when using rix/auth.
Mixing placeholder styles
Wrong:
rix.debug.format("{} {0}", "Rix");Use automatic placeholders:
rix.debug.format("{} {}", "Rix", "Debug");or explicit placeholders:
rix.debug.format("{0} {1}", "Rix", "Debug");Expecting advanced format specifiers
Wrong:
rix.debug.format("{:.2f}", 3.14159);Use simple placeholders:
rix.debug.format("value: {}", 3.14159);Forgetting deps
For a Vix project, do not put Rix packages in packages.
Use:
deps = [
"rix/rix",
]packages is for CMake package discovery.
deps is for Vix Registry packages.
What you should remember
Use the facade:
#include <rix.hpp>Print values:
rix.debug.print("Hello", "Rix");Print to stderr:
rix.debug.eprint("error:", "message");Format strings:
auto message = rix.debug.format("Package: {}", "rix/debug");Build printed output as a string:
auto line = rix.debug.sprint("rows:", 3);Inspect values:
rix.debug.inspect(message);For a Vix project, install Rix:
vix add rix/rix
vix installand use:
deps = [
"rix/rix",
]Use rix.debug for examples and development output.
Prefer Vix logging for real application logs.
Next step
Learn the printing helpers.
Next: Printing