Files
Library/CLAUDE.md
T
faumarayandClaude Sonnet 4.6 4fc129fb7e Initial commit: VoidLibrary C++23 modular library
Adds Logging module with thread-safe Logger base class, ScopedContext
RAII guards, Preset helpers, and a FileLogger standalone test/example.
Includes CMake module system for auto-discovery and CTest integration.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-25 21:28:29 +03:00

72 lines
3.3 KiB
Markdown

# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Build
```bash
# Configure (clang++, Ninja, Debug)
cmake -B build -S . -G Ninja -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Debug
# Build
cmake --build build
# Run all tests
ctest --test-dir build
# Run a single standalone test binary directly
./build/tests/test_standalone_Logging_FileLogger
```
Format code with:
```bash
clang-format -i <file>
```
## Architecture
VoidLibrary is a C++23 modular shared library. Each module is an independently installable CMake target under the `Void::` namespace.
### Module system
`cmake/Module.cmake` defines `void_add_module(NAME ...)`. The root `CMakeLists.txt` auto-discovers every subdirectory under `src/` and calls it. A module with only headers becomes an `INTERFACE` library; one with `.cpp` sources becomes a `SHARED` library.
Module layout:
- Headers: `include/Void/<ModuleName>/*.hpp`
- Sources: `src/<ModuleName>/*.cpp`
- CMake target: `Void_<ModuleName>` with alias `Void::<ModuleName>`
- Namespace: `Void::<ModuleName>`
To add a new module, create `src/<ModuleName>/` and populate it — the build system picks it up automatically. If a module needs special dependency wiring, drop a `module.cmake` file inside the source directory (see `cmake/module.cmake.template` for the pattern).
External dependencies are fetched via `cmake/Dependencies.cmake` using `FetchContent`; add new ones there and reference them via `EXTERNAL_DEPS` in `void_add_module`.
### Tests
`tests/CMakeLists.txt` defines two test categories:
| Category | Location | Binary | Links |
|---|---|---|---|
| Internal (kitchen-sink) | `tests/internal/*.cpp` | `VoidInternalTests` | all modules + `Void::Testing` |
| Standalone (isolated) | `tests/standalone/<ModuleName>/<name>.cpp` | `test_standalone_<ModuleName>_<name>` | its module only |
Standalone tests are preferred for testing a single module in isolation.
### Logging module
`Void::Logging::Logger` is an abstract base class. Derive from it to create a sink:
1. **Override `write(const Entry&)`** — called per-entry in Immediate mode and by the default `on_flush` fallback.
2. **Optionally override `on_flush(std::span<const Entry>)`** — for batch/vectored I/O (e.g. file sinks).
3. **Call `flush()` in your derived destructor** — the base destructor does not flush because calling a pure virtual from `~Logger` is UB. Any unflushed entries remaining after your destructor are silently dropped.
Key design points:
- Virtual extension points (`write`, `on_flush`) are called **outside** the internal mutex, so derived classes can do blocking I/O or acquire their own locks freely.
- `Level::Disabled` suppresses all output. Levels are ordered: `Trace < Debug < Info < Warning < Error < Fatal`.
- `push_scope(name)` returns a `[[nodiscard]]` RAII `ScopedContext` that emits `ScopeEnter`/`ScopeExit` entries and annotates all entries logged in that thread with a breadcrumb. `scope(name)` emits the boundary pair immediately without touching the scope stack.
- `make_preset(level, prefix)` returns a `Preset` — a non-owning callable that bakes in a level and optional prefix. Presets must not outlive their logger.
## Code style
Enforced by `.clang-format` (LLVM-based): 4-space indent (tabs), 80-column limit, Linux brace wrapping style, pointer alignment right.