diagprint 0.5.0

Pretty, structured diagnostics and reports for Rust applications.
Documentation
use super::Renderer;
use crate::Diagnostic;
#[derive(Debug, Default, Clone, Copy)]
pub struct PlainRenderer;
impl Renderer for PlainRenderer {
    fn render(&self, d: &Diagnostic) -> String {
        let mut o = format!(
            "{} app={} pid={} host={} session={} report={} {}{}: {}\n",
            d.timestamp.to_rfc3339(),
            d.application,
            d.pid,
            d.hostname,
            d.session_id,
            d.report_id,
            d.severity,
            d.code
                .as_ref()
                .map(|c| format!(" [{c}]"))
                .unwrap_or_default(),
            d.message
        );
        if let Some(c) = &d.cause {
            for (i, x) in c.iter().enumerate() {
                o.push_str(&format!("  {}└─ {}\n", "  ".repeat(i), x.message));
            }
        }
        for n in &d.notes {
            o.push_str(&format!("  note: {n}\n"));
        }
        if let Some(h) = &d.help {
            o.push_str(&format!("  help: {h}\n"));
        }
        o
    }
}