dioxus_provider/
log_utils.rs

1//! Internal logging utilities for consistent log formatting across the library
2//!
3//! This module provides macros that adapt log messages based on feature flags:
4//! - `tracing`: Enable/disable all logging (enabled by default)
5//! - `plain-logs`: When enabled with `tracing`, uses plain text prefixes instead of emojis
6//!
7//! ## Usage
8//!
9//! ```toml
10//! # Default: tracing enabled with emojis
11//! dioxus-provider = "0.1"
12//!
13//! # Disable all logging
14//! dioxus-provider = { version = "0.1", default-features = false }
15//!
16//! # Enable tracing with plain text (no emojis)
17//! dioxus-provider = { version = "0.1", features = ["plain-logs"] }
18//! ```
19
20/// Internal debug logging macro that respects the tracing feature flag
21#[macro_export]
22macro_rules! debug_log {
23    ($($arg:tt)*) => {
24        #[cfg(feature = "tracing")]
25        tracing::debug!($($arg)*);
26    };
27}
28
29/// Logs a cache hit with appropriate formatting
30#[macro_export]
31macro_rules! log_cache_hit {
32    ($($arg:tt)*) => {
33        #[cfg(all(feature = "tracing", not(feature = "plain-logs")))]
34        tracing::debug!("📊 [CACHE-HIT] {}", format!($($arg)*));
35        #[cfg(all(feature = "tracing", feature = "plain-logs"))]
36        tracing::debug!("[CACHE-HIT] {}", format!($($arg)*));
37    };
38}
39
40/// Logs a cache store operation with appropriate formatting
41#[macro_export]
42macro_rules! log_cache_store {
43    ($($arg:tt)*) => {
44        #[cfg(all(feature = "tracing", not(feature = "plain-logs")))]
45        tracing::debug!("📊 [CACHE-STORE] {}", format!($($arg)*));
46        #[cfg(all(feature = "tracing", feature = "plain-logs"))]
47        tracing::debug!("[CACHE-STORE] {}", format!($($arg)*));
48    };
49}
50
51/// Logs a cache invalidation with appropriate formatting
52#[macro_export]
53macro_rules! log_cache_invalidate {
54    ($($arg:tt)*) => {
55        #[cfg(all(feature = "tracing", not(feature = "plain-logs")))]
56        tracing::debug!("🗑️ [CACHE-INVALIDATE] {}", format!($($arg)*));
57        #[cfg(all(feature = "tracing", feature = "plain-logs"))]
58        tracing::debug!("[CACHE-INVALIDATE] {}", format!($($arg)*));
59    };
60}
61
62/// Logs a mutation start with appropriate formatting
63#[macro_export]
64macro_rules! log_mutation_start {
65    ($($arg:tt)*) => {
66        #[cfg(all(feature = "tracing", not(feature = "plain-logs")))]
67        tracing::debug!("🔄 [MUTATION] {}", format!($($arg)*));
68        #[cfg(all(feature = "tracing", feature = "plain-logs"))]
69        tracing::debug!("[MUTATION] {}", format!($($arg)*));
70    };
71}
72
73/// Logs a mutation success with appropriate formatting
74#[macro_export]
75macro_rules! log_mutation_success {
76    ($($arg:tt)*) => {
77        #[cfg(all(feature = "tracing", not(feature = "plain-logs")))]
78        tracing::debug!("✅ [MUTATION] {}", format!($($arg)*));
79        #[cfg(all(feature = "tracing", feature = "plain-logs"))]
80        tracing::debug!("[MUTATION-SUCCESS] {}", format!($($arg)*));
81    };
82}
83
84/// Logs a mutation error with appropriate formatting
85#[macro_export]
86macro_rules! log_mutation_error {
87    ($($arg:tt)*) => {
88        #[cfg(all(feature = "tracing", not(feature = "plain-logs")))]
89        tracing::debug!("❌ [MUTATION] {}", format!($($arg)*));
90        #[cfg(all(feature = "tracing", feature = "plain-logs"))]
91        tracing::debug!("[MUTATION-ERROR] {}", format!($($arg)*));
92    };
93}
94
95/// Logs an optimistic update with appropriate formatting
96#[macro_export]
97macro_rules! log_optimistic {
98    ($($arg:tt)*) => {
99        #[cfg(all(feature = "tracing", not(feature = "plain-logs")))]
100        tracing::debug!("⚡ [OPTIMISTIC] {}", format!($($arg)*));
101        #[cfg(all(feature = "tracing", feature = "plain-logs"))]
102        tracing::debug!("[OPTIMISTIC] {}", format!($($arg)*));
103    };
104}
105
106/// Logs a rollback operation with appropriate formatting
107#[macro_export]
108macro_rules! log_rollback {
109    ($($arg:tt)*) => {
110        #[cfg(all(feature = "tracing", not(feature = "plain-logs")))]
111        tracing::debug!("🔄 [ROLLBACK] {}", format!($($arg)*));
112        #[cfg(all(feature = "tracing", feature = "plain-logs"))]
113        tracing::debug!("[ROLLBACK] {}", format!($($arg)*));
114    };
115}