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
pub enum DebugLevel {
14
    /// Very detailed tracing information
15
    Trace,
16
    /// Debugging information
17
    Debug,
18
    /// General information
19
    Info,
20
    /// Warnings (potential issues)
21
    Warn,
22
    /// Errors
23
    Error,
24
}
25

            
26
impl Default for DebugLevel {
27
    fn default() -> Self {
28
        DebugLevel::Debug
29
    }
30
}
31

            
32
/// Categories for debug messages to enable filtering
33
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
34
#[repr(C)]
35
pub enum DebugCategory {
36
    /// General/uncategorized
37
    General,
38
    /// Window creation and management
39
    Window,
40
    /// Event loop processing
41
    EventLoop,
42
    /// Input events (mouse, keyboard, touch)
43
    Input,
44
    /// Layout calculation
45
    Layout,
46
    /// Text shaping and rendering
47
    Text,
48
    /// Display list generation
49
    DisplayList,
50
    /// WebRender scene building
51
    SceneBuilding,
52
    /// GPU rendering
53
    Rendering,
54
    /// Resource loading (fonts, images)
55
    Resources,
56
    /// Callbacks and user code
57
    Callbacks,
58
    /// Timer and animation
59
    Timer,
60
    /// HTTP debug server
61
    DebugServer,
62
    /// Platform-specific (macOS, Windows, Linux)
63
    Platform,
64
    /// Icon resolution
65
    Icon,
66
}
67

            
68
impl Default for DebugCategory {
69
    fn default() -> Self {
70
        DebugCategory::General
71
    }
72
}
73

            
74
// Convenience macros for logging with automatic category and format.
75
//
76
// Usage:
77
//   log_debug!(logger, Layout, "Processing {} nodes", count);
78
//   log_info!(logger, Window, "Window created with id {}", id);
79

            
80
/// Log a message at trace level
81
#[macro_export]
82
macro_rules! log_trace {
83
    ($logger:expr, $category:ident, $($arg:tt)*) => {
84
        if let Some(ref mut logger) = $logger {
85
            logger.trace($crate::debug::DebugCategory::$category, format!($($arg)*));
86
        }
87
    };
88
}
89

            
90
/// Log a message at debug level
91
#[macro_export]
92
macro_rules! log_debug {
93
    ($logger:expr, $category:ident, $($arg:tt)*) => {
94
        if let Some(ref mut logger) = $logger {
95
            logger.debug($crate::debug::DebugCategory::$category, format!($($arg)*));
96
        }
97
    };
98
}
99

            
100
/// Log a message at info level
101
#[macro_export]
102
macro_rules! log_info {
103
    ($logger:expr, $category:ident, $($arg:tt)*) => {
104
        if let Some(ref mut logger) = $logger {
105
            logger.info($crate::debug::DebugCategory::$category, format!($($arg)*));
106
        }
107
    };
108
}
109

            
110
/// Log a message at warn level
111
#[macro_export]
112
macro_rules! log_warn {
113
    ($logger:expr, $category:ident, $($arg:tt)*) => {
114
        if let Some(ref mut logger) = $logger {
115
            logger.warn($crate::debug::DebugCategory::$category, format!($($arg)*));
116
        }
117
    };
118
}
119

            
120
/// Log a message at error level
121
#[macro_export]
122
macro_rules! log_error {
123
    ($logger:expr, $category:ident, $($arg:tt)*) => {
124
        if let Some(ref mut logger) = $logger {
125
            logger.error($crate::debug::DebugCategory::$category, format!($($arg)*));
126
        }
127
    };
128
}
129