Skip to main content

azul_core/
debug.rs

1//! Debug logging types and macros for Azul.
2//!
3//! Provides [`DebugLevel`], [`DebugCategory`], and convenience macros
4//! (`log_trace!`, `log_debug!`, `log_info!`, `log_warn!`, `log_error!`)
5//! for structured logging throughout the codebase.
6//!
7//! The HTTP debug server implementation lives in
8//! `dll/src/desktop/shell2/common/debug_server.rs`.
9
10/// Debug message severity level
11#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
12#[repr(C)]
13#[derive(Default)]
14pub enum DebugLevel {
15    /// Very detailed tracing information
16    Trace,
17    /// Debugging information
18    #[default]
19    Debug,
20    /// General information
21    Info,
22    /// Warnings (potential issues)
23    Warn,
24    /// Errors
25    Error,
26}
27
28/// Categories for debug messages to enable filtering
29#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
30#[repr(C)]
31#[derive(Default)]
32pub enum DebugCategory {
33    /// General/uncategorized
34    #[default]
35    General,
36    /// Window creation and management
37    Window,
38    /// Event loop processing
39    EventLoop,
40    /// Input events (mouse, keyboard, touch)
41    Input,
42    /// Layout calculation
43    Layout,
44    /// Text shaping and rendering
45    Text,
46    /// Display list generation
47    DisplayList,
48    /// `WebRender` scene building
49    SceneBuilding,
50    /// GPU rendering
51    Rendering,
52    /// Resource loading (fonts, images)
53    Resources,
54    /// Callbacks and user code
55    Callbacks,
56    /// Timer and animation
57    Timer,
58    /// HTTP debug server
59    DebugServer,
60    /// Platform-specific (macOS, Windows, Linux)
61    Platform,
62    /// Icon resolution
63    Icon,
64}
65
66// Convenience macros for logging with automatic category and format.
67//
68// Usage:
69//   log_debug!(logger, Layout, "Processing {} nodes", count);
70//   log_info!(logger, Window, "Window created with id {}", id);
71
72/// Log a message at trace level
73#[macro_export]
74macro_rules! log_trace {
75    ($logger:expr, $category:ident, $($arg:tt)*) => {
76        if let Some(ref mut logger) = $logger {
77            logger.trace($crate::debug::DebugCategory::$category, format!($($arg)*));
78        }
79    };
80}
81
82/// Log a message at debug level
83#[macro_export]
84macro_rules! log_debug {
85    ($logger:expr, $category:ident, $($arg:tt)*) => {
86        if let Some(ref mut logger) = $logger {
87            logger.debug($crate::debug::DebugCategory::$category, format!($($arg)*));
88        }
89    };
90}
91
92/// Log a message at info level
93#[macro_export]
94macro_rules! log_info {
95    ($logger:expr, $category:ident, $($arg:tt)*) => {
96        if let Some(ref mut logger) = $logger {
97            logger.info($crate::debug::DebugCategory::$category, format!($($arg)*));
98        }
99    };
100}
101
102/// Log a message at warn level
103#[macro_export]
104macro_rules! log_warn {
105    ($logger:expr, $category:ident, $($arg:tt)*) => {
106        if let Some(ref mut logger) = $logger {
107            logger.warn($crate::debug::DebugCategory::$category, format!($($arg)*));
108        }
109    };
110}
111
112/// Log a message at error level
113#[macro_export]
114macro_rules! log_error {
115    ($logger:expr, $category:ident, $($arg:tt)*) => {
116        if let Some(ref mut logger) = $logger {
117            logger.error($crate::debug::DebugCategory::$category, format!($($arg)*));
118        }
119    };
120}