Expand description
Debug logging helpers used by Hotaru internals. Debug logging module for development-time diagnostics.
Provides conditional compilation macros that enable detailed logging
during development while ensuring zero runtime overhead in production
builds. All macros are controlled by the dev-log feature flag.
§Three-arm design (dev-log × std / embedded)
Each macro has three cfg-arms so no build ever pulls in std machinery it doesn’t want:
dev-log | std / embedded | Expansion |
|---|---|---|
| off | either | nothing — arguments are not evaluated. |
| on | std | println! / eprintln! with [LEVEL] prefix (the classic behaviour). |
| on | embedded | Hollow expansion — let _ = core::format_args!(...). Arguments are still evaluated so unused_variables warnings at call sites stay quiet, but no formatting, allocation, or IO happens. |
The hollow embedded arm exists because embedded builds are #![no_std]
— println! / eprintln! are gone, and format! allocates via
alloc (which is available but wasteful for a no-op). format_args!
is core:: and creates a stack-only core::fmt::Arguments value at
zero allocation cost. Wrapping in let _ = ...; marks the resulting
value as intentionally discarded.
§Future: hooking a real embedded logger
When HCR picks an embedded logger (defmt / semihosting / RTT / the
log crate), route the hollow arm through a user-installed sink
function — the macro body changes, call sites don’t. Design sketch:
a static LOGGER: OnceCell<fn(core::fmt::Arguments<'_>)> that the
user’s #[entry] installs once, and the embedded arm calls it if
present. Deferred until an actual logger is chosen.
§Usage
Enable the feature in your Cargo.toml or via command line:
cargo run --features "dev-log"Then import and use the macros:
use hotaru_core::{debug_log, debug_error};
debug_log!("Server started on port {}", 8080);
debug_error!("Connection failed: {}", err);