Skip to content

docs: add architectural design document for 1.0 - #247

Merged
tisonkun merged 19 commits into
mainfrom
docs/design
Nov 25, 2026
Merged

tisonkun merged 19 commits into
mainfrom
docs/design

Conversation

@tisonkun

@tisonkun tisonkun commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add DESIGN.md at the repository root defining the architectural model, public contracts, and target 1.0 boundaries across logforth-core and its surrounding crates:

  1. Scope & Versioning: Zero-dependency logforth-core 1.0 vs independent 0.x facade, appenders, layouts, filters, diagnostics, and bridges.
  2. Pipeline Topology & Assembly: Separation of source location (module_path), channel (Logger), and fan-out (Dispatch); Logger as a lightweight Clone handle with const fn Logger::noop(); Arc<T> and &'static T component sharing; ErrorSink dispatch-to-logger fallback vs Dispatch-scoped Filter and Diagnostic.
  3. Core Extension Traits: Object-safe trait contracts (Filter::bounds + Filter::filter, Diagnostic, Layout, Append, ErrorSink), Diagnostics<'a> zero-copy view, and append-only Layout::format(..., buf: &mut Vec<u8>) buffer semantics.
  4. Filtering & Fast-Path Pruning: 24 OpenTelemetry severity levels, ternary FilterResult (Accept, Reject, Neutral), backwards-inducted LevelMask(u32) pruning, Logger::enabled(level), and RustLogFilter filtering on Record::module_path().
  5. Structured Key-Values & Operational Safety: Zero-allocation Copy + Send + Sync borrowed Value<'a>, unified #[non_exhaustive] ValueView<'a>, lossless ordered ValueOwned slices (From<&'a ValueOwned> for Value<'a> and optional serde constructors), structured built-in diagnostics with !Send scope guards, LocalKey::try_with teardown safety, and non-panicking runtime error propagation.
  6. Native Macros & Ecosystem Interop: Explicit ["key" = expr] rustfmt-valid and .await Send-safe macro expansion, plus bidirectional log and tracing adapters (handling legacy target overrides and loop prevention).

Add `DESIGN.md` defining the architectural model, public contracts, and target `1.0` boundaries for `logforth-core` and its surrounding crates:
- Pipeline topology separating source location, category (`target`), channel (`Logger`), and fan-out (`Dispatch`), plus `Arc<T>` DAG sharing and `ErrorSink` fallback rules.
- Core extension traits (`Filter`, `Diagnostic`, `Layout`, `Append`, `ErrorSink`), opaque `Diagnostics` view, and append-only `Layout` byte buffer contract.
- Ternary `FilterResult` (`Accept`, `Reject`, `Neutral`) paired with backwards-inducted 24-level `LevelMask` fast-path pruning.
- Structured key-value contracts (`ValueView::Str`, causal `ValueView::Error`, lossless ordered `ValueOwned`), operational safety invariants, `rustfmt`- and `Send`-safe native macros, bidirectional `log`/`tracing` interop, and external registry boundary.

Signed-off-by: tison <wander4096@gmail.com>
Rewrite `DESIGN.md` as a self-contained target specification rather than a diff against existing `0.x` internals:
- Drop special `target` fields and `FilterCriteria` in favor of `Record::module_path`, `Logger::level_enabled`, and single-pass `Filter::check(&Record, Diagnostics)` paired with `Filter::bounds`.
- Add the `Diagnostics<'a>` view sketch, retain `#[non_exhaustive]` and existing string variants on `ValueView`, separate normative contracts from examples, and remove parenthetical clutter and chat-specific comparisons.

Signed-off-by: tison <wander4096@gmail.com>
State `Record` fields, dynamic filter mask semantics, and `Value`/`ValueView` conversions as complete standalone contracts rather than listing incremental additions or exclusions relative to pre-1.0 code.

Signed-off-by: tison <wander4096@gmail.com>
…records

Unify pre-construction pruning on `Logger::enabled(level: Level) -> bool` and let `LogBridge::enabled` delegate to it directly instead of keeping a separate `Logger::enabled(&Record)` path or constructing half-populated records.

Signed-off-by: tison <wander4096@gmail.com>
Keep `kv` primitives orthogonal and let callers format causal error chains with their own wrapper types rather than baking an opinionated error value variant into `logforth-core`.

Signed-off-by: tison <wander4096@gmail.com>
…tion

Define `Logger` as a lightweight `Clone` handle over a shared pipeline with static or `Arc<AtomicLevelMask>` per-handle level gates so derived module or subsystem handles share dispatches and `flush` while achieving `O(1)` callsite pruning. Keep `RustLogFilter` strictly `O(1)` on `Record::module_path()` and expose its directive matcher for custom filters rather than adding KV-scanning options.

Signed-off-by: tison <wander4096@gmail.com>
Align the private backing enum name of `Diagnostics` with `ValueState`, `MapValueState`, and `ListValueState` in `logforth-core`.

Signed-off-by: tison <wander4096@gmail.com>
Document in Ecosystem Interop that inbound `log` and `tracing` adapters populate `Record::module_path` and only emit a `"target"` key-value pair when an upstream event explicitly overrides `target`, removing negative phrasing elsewhere.

Signed-off-by: tison <wander4096@gmail.com>
State component sharing and module-level filtering directly instead of referencing nonexistent provider wrappers or key-value scanning options.

Signed-off-by: tison <wander4096@gmail.com>
…SIGN.md

Drop the speculative `Registry Boundary` section and per-handle `AtomicLevelMask` / `LazyLock<Logger>` machinery from `DESIGN.md`, keeping `Logger` focused on a shared immutable pipeline with `const fn Logger::noop()`.

Signed-off-by: tison <wander4096@gmail.com>
…ctures

Specify `From<&'a ValueOwned> for Value<'a>` and optional `serde`-backed `ValueOwned` construction so nested custom structures integrate cleanly into `KeyValues<'a>` as concrete value trees.

Signed-off-by: tison <wander4096@gmail.com>
…tracts

Address final review findings in `DESIGN.md`:
- Retain `LevelFilter` items in `Dispatch` filter chains so preceding dynamic `Accept` filters cannot drop downstream level thresholds, while testing each branch's `LevelMask` in `Logger::log`.
- Specify `fmt::write` fallback for infallible `Record::to_owned` and `ValueView::to_owned` snapshot conversions, and `from_serde` / `try_from_serde` error behavior.
- Mark `ThreadLocalDiagnostic` scope guards `!Send` with shadowed-value restoration, and place the shared bridge reentrancy guard in `logforth-core` across both inbound bridges.

Signed-off-by: tison <wander4096@gmail.com>
Specify that `RustLogFilter` exposes named-directive lookup so custom filters can match explicit key-value categories without prematurely triggering the global fallback directive before `module_path` matching.

Signed-off-by: tison <wander4096@gmail.com>
Use `check` consistently across `Filter::check` and `RustLogFilter`'s module and named-directive check descriptions.

Signed-off-by: tison <wander4096@gmail.com>
Align `Filter::filter` with `Append::append` and `ErrorSink::sink`, keeping `test` reserved for boolean predicates such as `LevelFilter::test` and `LevelMask::test`.

Signed-off-by: tison <wander4096@gmail.com>
…nsion

- Make `Value<'a>` `Clone` (capable of holding `ValueOwned` alongside borrowed variants) so workspace types can implement `From<&'a T> for Value<'a>` directly, while `Value::debug`, `Value::display`, and `Value::serde` cover explicit conversions without `value-bag` or sigil DSLs.
- Standardize native macro key-value entries on explicit `"key" = expr` string literal keys without identifier shorthands or sigils, and specify `Send`-preserving `match` binding across `.await`.

Signed-off-by: tison <wander4096@gmail.com>
Require `+ Sync` on `Value::debug` and `Value::display` so `Value<'a>` itself is `Send + Sync` without extra wrapper types, working uniformly inside and outside macros across `.await` points.

Signed-off-by: tison <wander4096@gmail.com>
- Keep `Value<'a>` strictly `Copy` as a pure borrowed carrier (including `&'a ValueOwned`), preserving the clean separation between `Value<'a>` (borrowed input), `ValueOwned` (`'static` owned), and `ValueView<'a>` (unified read-only projection).
- Replace `permanent contract` with `stable contract` in `Scope and Crate Versioning`, and convert the trailing bullet list in `Core Extension Traits` into prose paragraphs consistent with the rest of the section.

Signed-off-by: tison <wander4096@gmail.com>
Streamline parenthetical clauses in `Structured Key-Values and Diagnostics` and `Error Handling and Operational Safety` for consistent declarative prose across the document.

Signed-off-by: tison <wander4096@gmail.com>
@tisonkun
tisonkun merged commit ef8c70f into main Nov 25, 2026
9 checks passed
@tisonkun
tisonkun deleted the docs/design branch November 25, 2026 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant