subspace_core/diagnostics/
logging.rs1use crate::log::{Level, Logger};
2
3use super::{ErrorDetails, LocalDiagnostics};
4
5impl LocalDiagnostics {
6 pub fn log_error(&self, logger: &Logger, surface: &str, error: &ErrorDetails) {
10 let fields = structured_fields(self, surface, error);
11 let borrowed: Vec<_> = fields
12 .iter()
13 .map(|(name, value)| (*name, value.as_str()))
14 .collect();
15 let message = self
16 .redaction
17 .error_text(&error.title, &error.private_values);
18 logger.record(Level::Error, message, &borrowed);
19 }
20}
21
22fn structured_fields(
23 snapshot: &LocalDiagnostics,
24 surface: &str,
25 error: &ErrorDetails,
26) -> Vec<(&'static str, String)> {
27 let mut fields = vec![(
28 "surface",
29 snapshot
30 .redaction
31 .error_text(surface, &error.private_values),
32 )];
33 fields.extend(
34 super::markdown::error_fields(snapshot, error)
35 .into_iter()
36 .map(|(_, key, value)| (key, value)),
37 );
38 fields.push((
39 "details",
40 snapshot.local_copy(Some(error)).markdown().to_owned(),
41 ));
42 fields
43}