1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2024-2026 Jonathan Shook
// SPDX-License-Identifier: Apache-2.0
//! Diagnostic logging sink for nmbrs-metrics.
//!
//! Reporters and instruments occasionally need to emit operational
//! warnings (sqlite write failures, histogram record failures, etc.).
//! To avoid corrupting TUI output with raw `eprintln!`, all such
//! warnings go through [`warn`] which routes to a pluggable callback.
//!
//! Consumers (like `nmbrs-runtime`) install a callback at startup that
//! forwards into their observer/log infrastructure. If no callback is
//! set, the default falls back to `eprintln!` so standalone/test use
//! still surfaces messages.
use OnceLock;
/// Type of the installed warn callback.
pub type WarnFn = fn;
/// Type of the installed info callback. INFO-level messages are routed
/// through the same TUI-safe sink pattern as warnings, so noteworthy
/// startup state (e.g. auto-inserted cadence layers โ SRD-42 ยง"Tree
/// Construction โ Logging") doesn't bypass the observer infrastructure.
pub type InfoFn = fn;
static WARN_FN: = new;
static INFO_FN: = new;
/// Install the warn callback. Called once at startup. If called more
/// than once, the first install wins (consistent with the rest of the
/// nmbrs per-process singleton pattern).
/// Install the info callback. Same first-install-wins semantics as
/// [`set_warn_fn`].
/// Emit a warning through the configured sink, or stderr if none.
/// Emit an INFO message through the configured sink, or stderr if none.
/// Use sparingly โ reserved for noteworthy startup/lifecycle state
/// that should be grep-able from a run log without enabling debug.