Logwise Procedural Macros
This crate provides procedural macros for the logwise logging library, generating efficient
structured logging code at compile time. The macros transform format strings with key-value
pairs into optimized logging calls that use the PrivateFormatter system.
Architecture
Each logging macro follows a consistent three-phase pattern:
- Pre-phase: Creates a
LogRecordusing*_pre()functions with location metadata - Format phase: Uses
PrivateFormatterto write structured data vialformat_impl - Post-phase: Completes logging using
*_post()functions (sync or async variants)
Log Levels and Build Configuration
The macros respect logwise's opinionated logging levels:
trace_*: Debug builds only, per-thread activation viaContext::currently_tracing()debuginternal_*: Debug builds only, requiresdeclare_logging_domain!()at crate rootinfo_*: Debug builds only, for supporting downstream crateswarn_*,error_*,perfwarn_*: Available in all builds
Usage Example
use *;
// This macro call:
// logwise::info_sync!("User {name} has {count} items", name="alice", count=42);
// Expands to approximately:
// {
// let mut record = logwise::hidden::info_sync_pre(file!(), line!(), column!());
// let mut formatter = logwise::hidden::PrivateFormatter::new(&mut record);
// formatter.write_literal("User ");
// formatter.write_val("alice");
// formatter.write_literal(" has ");
// formatter.write_val(42);
// formatter.write_literal(" items");
// logwise::hidden::info_sync_post(record);
// }
Key-Value Parsing
Format strings support embedded key-value pairs:
- Keys are extracted from
{key}placeholders in the format string - Values are provided as
key=valueparameters after the format string - The parser handles complex Rust expressions as values, including method calls and literals
Privacy Integration
These macros integrate with logwise's privacy system via the Loggable trait.
Values are processed through formatter.write_val() which respects privacy constraints.