#[cfg(feature = "structured_logging")]
use super::slice_to_cow_utf8;
use super::{DiagnosticStream, Diagnostics, Record};
use log::{Level, warn};
pub fn log_diagnostics(handle: &(impl Diagnostics + ?Sized)) {
if log::max_level() < Level::Warn {
return;
}
let mut diagnostic_stream = DiagnosticStream::new(handle);
while let Some(record) = diagnostic_stream.next() {
log_diagnostic_record(record);
}
}
pub fn log_diagnostic_record(record: &Record) {
#[cfg(not(feature = "structured_logging"))]
warn!("{record}");
#[cfg(feature = "structured_logging")]
warn!(
target: "odbc",
state = record.state.as_str(),
native_error = record.native_error;
"{}", slice_to_cow_utf8(&record.message)
);
}