odbc_api/handles/
logging.rs1#[cfg(feature = "structured_logging")]
2use super::slice_to_cow_utf8;
3use super::{DiagnosticStream, Diagnostics, Record};
4use log::{Level, warn};
5
6pub fn log_diagnostics(handle: &(impl Diagnostics + ?Sized)) {
9 if log::max_level() < Level::Warn {
10 return;
13 }
14
15 let mut diagnostic_stream = DiagnosticStream::new(handle);
16
17 while let Some(record) = diagnostic_stream.next() {
19 log_diagnostic_record(record);
20 }
21}
22
23pub fn log_diagnostic_record(record: &Record) {
26 #[cfg(not(feature = "structured_logging"))]
27 warn!("{record}");
28 #[cfg(feature = "structured_logging")]
29 warn!(
30 target: "odbc",
31 state = record.state.as_str(),
32 native_error = record.native_error;
33 "{}", slice_to_cow_utf8(&record.message)
34 );
35}