use crate::log::{Level, Logger};
use super::{ErrorDetails, LocalDiagnostics};
impl LocalDiagnostics {
pub fn log_error(&self, logger: &Logger, surface: &str, error: &ErrorDetails) {
let fields = structured_fields(self, surface, error);
let borrowed: Vec<_> = fields
.iter()
.map(|(name, value)| (*name, value.as_str()))
.collect();
let message = self
.redaction
.error_text(&error.title, &error.private_values);
logger.record(Level::Error, message, &borrowed);
}
}
fn structured_fields(
snapshot: &LocalDiagnostics,
surface: &str,
error: &ErrorDetails,
) -> Vec<(&'static str, String)> {
let mut fields = vec![(
"surface",
snapshot
.redaction
.error_text(surface, &error.private_values),
)];
fields.extend(
super::markdown::error_fields(snapshot, error)
.into_iter()
.map(|(_, key, value)| (key, value)),
);
fields.push((
"details",
snapshot.local_copy(Some(error)).markdown().to_owned(),
));
fields
}