Expand description
§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 logwise_proc::*;
// 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.
Macros§
- debuginternal_
async - Asynchronous debug-internal logging (debug builds only).
- debuginternal_
sync - Synchronous debug-internal logging (debug builds only).
- error_
async - Asynchronous error-level logging (all builds).
- error_
sync - Synchronous error-level logging (all builds).
- info_
async - Asynchronous info-level logging (debug builds only).
- info_
sync - Synchronous info-level logging (debug builds only).
- lformat
- Low-level macro for generating formatter calls from format strings.
- mandatory_
async - Asynchronous mandatory-level logging (all builds).
- mandatory_
sync - Synchronous mandatory-level logging (all builds).
- perfwarn
- Block-scoped performance warning interval (all builds).
- perfwarn_
begin - Begin a performance warning interval (all builds).
- perfwarn_
begin_ if - Conditional performance warning interval.
- profile_
async - Asynchronous profile-level logging (all builds).
- profile_
begin - Begin a profile interval (all builds).
- profile_
sync - Synchronous profile-level logging (all builds).
- trace_
async - Asynchronous trace-level logging (debug builds only, per-thread activation).
- trace_
sync - Synchronous trace-level logging (debug builds only, per-thread activation).
- warn_
sync - Synchronous warning-level logging (all builds).
Attribute Macros§
- profile
- Attribute macro to automatically profile a function’s execution time.