|
1 | | -# rix/debug |
| 1 | +# @rix/debug |
2 | 2 |
|
3 | | -Debug printing, formatting, logging, and inspection utilities for Rix. |
| 3 | +Debug utilities for Rix. |
4 | 4 |
|
5 | | -`rix/debug` is part of Rix, the userland package layer for the Vix.cpp ecosystem. |
| 5 | +`@rix/debug` provides a small set of developer-focused tools for C++ projects: |
6 | 6 |
|
7 | | -The source code lives in its own repository. This folder only keeps the official package entry used by the Rix umbrella repository. |
| 7 | +- formatted strings |
| 8 | +- simple logging |
| 9 | +- value inspection |
| 10 | +- print helpers |
8 | 11 |
|
9 | | -## Install |
| 12 | +It can be used as an independent Rix package, or through the unified `@rix/rix` facade. |
| 13 | + |
| 14 | +## Installation |
10 | 15 |
|
11 | 16 | ```bash |
12 | 17 | vix add @rix/debug |
13 | 18 | vix install |
14 | 19 | ``` |
15 | 20 |
|
16 | | -## Use |
| 21 | +## Basic usage |
17 | 22 |
|
18 | 23 | ```cpp |
19 | 24 | #include <rix/debug.hpp> |
20 | 25 |
|
21 | 26 | int main() |
22 | 27 | { |
23 | | - rixlib::debug::Debug debug; |
| 28 | + rixlib::debug::Debug debug{}; |
24 | 29 |
|
25 | | - debug.print("Hello {}", "Rix"); |
| 30 | + debug.print("Hello", "Rix"); |
26 | 31 |
|
27 | 32 | auto text = debug.format("Package: {}", "rix/debug"); |
28 | 33 |
|
29 | 34 | debug.log("loaded {} rows", 3); |
30 | 35 | debug.log.warn("slow request: {}ms", 120); |
31 | 36 |
|
32 | 37 | debug.inspect(text); |
| 38 | + |
| 39 | + return 0; |
33 | 40 | } |
34 | 41 | ``` |
35 | 42 |
|
36 | | -## Repository |
| 43 | +Output: |
37 | 44 |
|
38 | 45 | ```txt |
39 | | -https://github.com/rixcpp/debug |
| 46 | +Hello Rix |
| 47 | +[debug] loaded 3 rows |
| 48 | +[warn] slow request: 120ms |
| 49 | +Package: rix/debug |
40 | 50 | ``` |
41 | 51 |
|
42 | | -## Package |
| 52 | +## Formatting |
| 53 | + |
| 54 | +`debug.format` supports simple placeholder-based formatting. |
| 55 | + |
| 56 | +```cpp |
| 57 | +auto message = debug.format("Hello {}", "Rix"); |
| 58 | +auto result = debug.format("{0} + {0} = {1}", 2, 4); |
| 59 | +auto escaped = debug.format("{{ value }} = {}", 42); |
| 60 | +``` |
| 61 | + |
| 62 | +Supported placeholders: |
43 | 63 |
|
44 | 64 | ```txt |
45 | | -rix/debug |
| 65 | +{} automatic argument indexing |
| 66 | +{0} explicit positional indexing |
| 67 | +{{ escaped opening brace |
| 68 | +}} escaped closing brace |
46 | 69 | ``` |
47 | 70 |
|
48 | | -## Namespace |
| 71 | +Format specifiers such as `{:>10}` or `{:.2f}` are intentionally not supported. |
| 72 | + |
| 73 | +## Logging |
49 | 74 |
|
50 | 75 | ```cpp |
51 | | -rixlib::debug |
| 76 | +debug.log("loaded {} rows", 3); |
| 77 | +debug.log.info("server started"); |
| 78 | +debug.log.warn("slow request: {}ms", 120); |
| 79 | +debug.log.error("failed: {}", "timeout"); |
| 80 | +``` |
| 81 | + |
| 82 | +Output: |
| 83 | + |
| 84 | +```txt |
| 85 | +[debug] loaded 3 rows |
| 86 | +[info] server started |
| 87 | +[warn] slow request: 120ms |
| 88 | +[error] failed: timeout |
52 | 89 | ``` |
53 | 90 |
|
54 | | -## CMake target |
| 91 | +## Printing |
| 92 | + |
| 93 | +`debug.print` is not a formatter. |
| 94 | + |
| 95 | +It prints values separated by spaces. |
55 | 96 |
|
56 | | -```cmake |
57 | | -rix::debug |
| 97 | +```cpp |
| 98 | +debug.print("Hello", "Rix"); |
| 99 | +debug.print(1, 2, 3); |
58 | 100 | ``` |
59 | 101 |
|
60 | | -## Manifest |
| 102 | +Output: |
61 | 103 |
|
62 | 104 | ```txt |
63 | | -packages/debug/vix.json |
| 105 | +Hello Rix |
| 106 | +1 2 3 |
64 | 107 | ``` |
65 | 108 |
|
66 | | -## Role in Rix |
| 109 | +For formatted strings, use `debug.format` or `debug.log`. |
67 | 110 |
|
68 | | -Rix does not embed package source code. |
| 111 | +```cpp |
| 112 | +debug.print(debug.format("Hello {}", "Rix")); |
| 113 | +``` |
69 | 114 |
|
70 | | -The real library lives in: |
| 115 | +## Inspection |
71 | 116 |
|
72 | | -```txt |
73 | | -github.com/rixcpp/debug |
| 117 | +```cpp |
| 118 | +debug.inspect(42); |
| 119 | + |
| 120 | +auto value = debug.inspect.to_string(true); |
| 121 | + |
| 122 | +bool ok = debug.inspect.check(42, 42); |
| 123 | +``` |
| 124 | + |
| 125 | +Inspection is useful for debugging values, containers, optional values, variants, and other supported C++ types. |
| 126 | + |
| 127 | +## Independent API |
| 128 | + |
| 129 | +You can also use the free functions directly. |
| 130 | + |
| 131 | +```cpp |
| 132 | +#include <rix/debug.hpp> |
| 133 | + |
| 134 | +int main() |
| 135 | +{ |
| 136 | + rixlib::print("Hello", "Rix"); |
| 137 | + |
| 138 | + auto text = rixlib::format("Package: {}", "rix/debug"); |
| 139 | + |
| 140 | + rixlib::inspect(text); |
| 141 | + |
| 142 | + return 0; |
| 143 | +} |
74 | 144 | ``` |
75 | 145 |
|
76 | | -The Rix facade mounts this package as: |
| 146 | +## Unified Rix facade |
| 147 | + |
| 148 | +When used through `@rix/rix`, the debug package is mounted under `rix.debug`. |
77 | 149 |
|
78 | 150 | ```cpp |
79 | | -rix.debug.print(...) |
80 | | -rix.debug.format(...) |
81 | | -rix.debug.log(...) |
82 | | -rix.debug.inspect(...) |
| 151 | +#include <rix.hpp> |
| 152 | + |
| 153 | +int main() |
| 154 | +{ |
| 155 | + rix.debug.print("Hello", "Rix"); |
| 156 | + rix.debug.log("loaded {} rows", 3); |
| 157 | + |
| 158 | + return 0; |
| 159 | +} |
| 160 | +``` |
| 161 | + |
| 162 | +## Design |
| 163 | + |
| 164 | +`@rix/debug` is intentionally small and focused. |
| 165 | + |
| 166 | +It does not try to replace full logging frameworks or formatting libraries. Its role is to provide simple debugging primitives that are easy to use in Rix-based C++ projects. |
| 167 | + |
| 168 | +The package exposes two layers: |
| 169 | + |
| 170 | +```txt |
| 171 | +rixlib::format(...) |
| 172 | +rixlib::print(...) |
| 173 | +rixlib::inspect(...) |
83 | 174 | ``` |
| 175 | + |
| 176 | +and the object-style API: |
| 177 | + |
| 178 | +```txt |
| 179 | +rixlib::debug::Debug |
| 180 | +``` |
| 181 | + |
| 182 | +This keeps the package usable on its own while allowing the unified Rix facade to mount it cleanly as: |
| 183 | + |
| 184 | +```txt |
| 185 | +rix.debug |
| 186 | +``` |
| 187 | + |
| 188 | +## Build |
| 189 | + |
| 190 | +```bash |
| 191 | +vix build |
| 192 | +``` |
| 193 | + |
| 194 | +## Run example |
| 195 | + |
| 196 | +```bash |
| 197 | +vix run |
| 198 | +``` |
| 199 | + |
| 200 | +## Tests |
| 201 | + |
| 202 | +```bash |
| 203 | +vix tests |
| 204 | +``` |
| 205 | + |
| 206 | +## License |
| 207 | + |
| 208 | +MIT |
0 commit comments