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
29/// Categories for debug messages to enable filtering
30#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
31#[repr(C)]
32#[derive(Default)]
33pub enum DebugCategory {
34    /// General/uncategorized
35    #[default]
36    General,
37    /// Window creation and management
38    Window,
39    /// Event loop processing
40    EventLoop,
41    /// Input events (mouse, keyboard, touch)
42    Input,
43    /// Layout calculation
44    Layout,
45    /// Text shaping and rendering
46    Text,
47    /// Display list generation
48    DisplayList,
49    /// `WebRender` scene building
50    SceneBuilding,
51    /// GPU rendering
52    Rendering,
53    /// Resource loading (fonts, images)
54    Resources,
55    /// Callbacks and user code
56    Callbacks,
57    /// Timer and animation
58    Timer,
59    /// HTTP debug server
60    DebugServer,
61    /// Platform-specific (macOS, Windows, Linux)
62    Platform,
63    /// Icon resolution
64    Icon,
65}
66
67
68// Convenience macros for logging with automatic category and format.
69//
70// Usage:
71//   log_debug!(logger, Layout, "Processing {} nodes", count);
72//   log_info!(logger, Window, "Window created with id {}", id);
73
74/// Log a message at trace level
75#[macro_export]
76macro_rules! log_trace {
77    ($logger:expr, $category:ident, $($arg:tt)*) => {
78        if let Some(ref mut logger) = $logger {
79            logger.trace($crate::debug::DebugCategory::$category, format!($($arg)*));
80        }
81    };
82}
83
84/// Log a message at debug level
85#[macro_export]
86macro_rules! log_debug {
87    ($logger:expr, $category:ident, $($arg:tt)*) => {
88        if let Some(ref mut logger) = $logger {
89            logger.debug($crate::debug::DebugCategory::$category, format!($($arg)*));
90        }
91    };
92}
93
94/// Log a message at info level
95#[macro_export]
96macro_rules! log_info {
97    ($logger:expr, $category:ident, $($arg:tt)*) => {
98        if let Some(ref mut logger) = $logger {
99            logger.info($crate::debug::DebugCategory::$category, format!($($arg)*));
100        }
101    };
102}
103
104/// Log a message at warn level
105#[macro_export]
106macro_rules! log_warn {
107    ($logger:expr, $category:ident, $($arg:tt)*) => {
108        if let Some(ref mut logger) = $logger {
109            logger.warn($crate::debug::DebugCategory::$category, format!($($arg)*));
110        }
111    };
112}
113
114/// Log a message at error level
115#[macro_export]
116macro_rules! log_error {
117    ($logger:expr, $category:ident, $($arg:tt)*) => {
118        if let Some(ref mut logger) = $logger {
119            logger.error($crate::debug::DebugCategory::$category, format!($($arg)*));
120        }
121    };
122}
123