Skip to content

Commit 7ce988d

Browse files
committed
feat(debug): prepare v0.2.0
1 parent c6fe0b3 commit 7ce988d

10 files changed

Lines changed: 5090 additions & 103 deletions

File tree

README.md

Lines changed: 207 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,208 @@
1-
# Debug
1+
# @rix/debug
22

3-
Debug printing, formatting, logging, and inspection utilities for Rix.
3+
Debug utilities for Rix.
4+
5+
`@rix/debug` provides a small set of developer-focused tools for C++ projects:
6+
7+
- formatted strings
8+
- simple logging
9+
- value inspection
10+
- print helpers
11+
12+
It can be used as an independent Rix package, or through the unified `@rix/rix` facade.
13+
14+
## Installation
15+
16+
```bash
17+
vix add @rix/debug
18+
vix install
19+
```
20+
21+
## Basic usage
22+
23+
```cpp
24+
#include <rix/debug.hpp>
25+
26+
int main()
27+
{
28+
rixlib::debug::Debug debug{};
29+
30+
debug.print("Hello", "Rix");
31+
32+
auto text = debug.format("Package: {}", "rix/debug");
33+
34+
debug.log("loaded {} rows", 3);
35+
debug.log.warn("slow request: {}ms", 120);
36+
37+
debug.inspect(text);
38+
39+
return 0;
40+
}
41+
```
42+
43+
Output:
44+
45+
```txt
46+
Hello Rix
47+
[debug] loaded 3 rows
48+
[warn] slow request: 120ms
49+
Package: rix/debug
50+
```
51+
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:
63+
64+
```txt
65+
{} automatic argument indexing
66+
{0} explicit positional indexing
67+
{{ escaped opening brace
68+
}} escaped closing brace
69+
```
70+
71+
Format specifiers such as `{:>10}` or `{:.2f}` are intentionally not supported.
72+
73+
## Logging
74+
75+
```cpp
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
89+
```
90+
91+
## Printing
92+
93+
`debug.print` is not a formatter.
94+
95+
It prints values separated by spaces.
96+
97+
```cpp
98+
debug.print("Hello", "Rix");
99+
debug.print(1, 2, 3);
100+
```
101+
102+
Output:
103+
104+
```txt
105+
Hello Rix
106+
1 2 3
107+
```
108+
109+
For formatted strings, use `debug.format` or `debug.log`.
110+
111+
```cpp
112+
debug.print(debug.format("Hello {}", "Rix"));
113+
```
114+
115+
## Inspection
116+
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+
}
144+
```
145+
146+
## Unified Rix facade
147+
148+
When used through `@rix/rix`, the debug package is mounted under `rix.debug`.
149+
150+
```cpp
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(...)
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

examples/basic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
int main()
99
{
10-
rixlib::debug::Debug debug;
10+
rixlib::debug::Debug debug{};
1111

12-
debug.print("Hello {}", "Rix");
12+
debug.print("Hello", "Rix");
1313

1414
auto text = debug.format("Package: {}", "rix/debug");
1515

include/rix/debug.hpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,71 @@
66
#ifndef RIXCPP_DEBUG_INCLUDE_RIX_DEBUG_HPP_INCLUDED
77
#define RIXCPP_DEBUG_INCLUDE_RIX_DEBUG_HPP_INCLUDED
88

9+
#include <string>
10+
911
#include <rix/debug/format.hpp>
1012
#include <rix/debug/inspect.hpp>
1113
#include <rix/debug/log.hpp>
1214
#include <rix/debug/print.hpp>
1315

1416
namespace rixlib::debug
1517
{
18+
/**
19+
* @brief Object-style facade for the rix/debug package.
20+
*/
1621
class Debug
1722
{
1823
public:
24+
/**
25+
* @brief Placeholder-based formatting component.
26+
*/
1927
Format format{};
20-
Print print{};
28+
29+
/**
30+
* @brief Logging component.
31+
*/
2132
Log log{};
33+
34+
/**
35+
* @brief Inspection component.
36+
*/
2237
Inspect inspect{};
38+
39+
/**
40+
* @brief Print values separated by spaces, with a trailing newline.
41+
*/
42+
template <typename... Args>
43+
void print(const Args &...args) const
44+
{
45+
rixlib::print(args...);
46+
}
47+
48+
/**
49+
* @brief Print values to stderr.
50+
*/
51+
template <typename... Args>
52+
void eprint(const Args &...args) const
53+
{
54+
rixlib::eprint(args...);
55+
}
56+
57+
/**
58+
* @brief Debug-only print to stderr.
59+
*/
60+
template <typename... Args>
61+
void dprint(const Args &...args) const
62+
{
63+
rixlib::dprint(args...);
64+
}
65+
66+
/**
67+
* @brief Format printed values into a string.
68+
*/
69+
template <typename... Args>
70+
[[nodiscard]] std::string sprint(const Args &...args) const
71+
{
72+
return rixlib::sprint(args...);
73+
}
2374
};
2475
}
2576

0 commit comments

Comments
 (0)