2
2
3
3
use std:: os:: raw:: c_char;
4
4
5
+ #[ cfg( feature = "log" ) ]
5
6
use log:: { Level , logger, Record } ;
6
7
7
8
use crate :: QString ;
@@ -74,6 +75,7 @@ pub enum QtMsgType {
74
75
// QtSystemMsg = QtCriticalMsg
75
76
}
76
77
78
+ #[ cfg( feature = "log" ) ]
77
79
impl From < QtMsgType > for Level {
78
80
/// Mapping from Qt logging levels to Rust logging facade's levels.
79
81
///
@@ -97,6 +99,7 @@ impl From<QtMsgType> for Level {
97
99
}
98
100
}
99
101
102
+ #[ cfg( feature = "log" ) ]
100
103
impl From < Level > for QtMsgType {
101
104
/// Mapping back from Rust logging facade's levels to Qt logging levels.
102
105
///
@@ -130,6 +133,7 @@ pub fn install_message_handler(logger: extern "C" fn(QtMsgType, &QMessageLogCont
130
133
// It is called from Qt code, then it converts Qt logging data
131
134
// into Rust logging facade's log::Record object, and sends it
132
135
// to the currently active logger.
136
+ #[ cfg( feature = "log" ) ]
133
137
extern "C" fn log_capture ( msg_type : QtMsgType ,
134
138
context : & QMessageLogContext ,
135
139
message : & QString ) {
@@ -179,6 +183,7 @@ extern "C" fn log_capture(msg_type: QtMsgType,
179
183
/// [log]: https://docs.rs/log
180
184
/// [`log::Record`]: https://docs.rs/log/0.4.10/log/struct.Record.html
181
185
/// [lvl]: ./struct.QtMsgType.html
186
+ #[ cfg( feature = "log" ) ]
182
187
pub fn init_qt_to_rust ( ) {
183
188
// The reason it is named so complex instead of simple `init` is that
184
189
// such descriptive name is future-proof. Consider if someone someday
@@ -187,6 +192,7 @@ pub fn init_qt_to_rust() {
187
192
}
188
193
189
194
#[ cfg( test) ]
195
+ #[ cfg( feature = "log" ) ]
190
196
mod tests {
191
197
use super :: * ;
192
198
0 commit comments