odbc_api/handles/
logging.rs

1use super::{DiagnosticStream, Diagnostics};
2use log::{Level, warn};
3
4/// This function inspects all the diagnostics of an ODBC handle and logs their text messages. It
5/// is going to print placeholder characters, if it cannot convert the message to UTF-8.
6pub fn log_diagnostics(handle: &(impl Diagnostics + ?Sized)) {
7    if log::max_level() < Level::Warn {
8        // Early return to safe work creating all these log records in case we would not log
9        // anything.
10        return;
11    }
12
13    let mut diagnostic_stream = DiagnosticStream::new(handle);
14
15    // Log results, while there are diagnostic records
16    while let Some(record) = diagnostic_stream.next() {
17        warn!("{record}");
18    }
19}