2024-06-11 01:26:31 +00:00
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
|
|
2024-06-12 18:52:24 +00:00
|
|
|
use super::{
|
2025-02-23 01:17:45 -05:00
|
|
|
super::{Level, fmt},
|
2024-06-12 18:52:24 +00:00
|
|
|
Closure, Data,
|
|
|
|
|
};
|
|
|
|
|
use crate::Result;
|
2024-06-11 01:26:31 +00:00
|
|
|
|
2024-06-12 18:52:24 +00:00
|
|
|
pub fn fmt_html<S>(out: Arc<Mutex<S>>) -> Box<Closure>
|
2024-06-11 01:26:31 +00:00
|
|
|
where
|
|
|
|
|
S: std::fmt::Write + Send + 'static,
|
|
|
|
|
{
|
2024-06-12 18:52:24 +00:00
|
|
|
fmt(fmt::html, out)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn fmt_markdown<S>(out: Arc<Mutex<S>>) -> Box<Closure>
|
|
|
|
|
where
|
|
|
|
|
S: std::fmt::Write + Send + 'static,
|
|
|
|
|
{
|
|
|
|
|
fmt(fmt::markdown, out)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn fmt<F, S>(fun: F, out: Arc<Mutex<S>>) -> Box<Closure>
|
|
|
|
|
where
|
|
|
|
|
F: Fn(&mut S, &Level, &str, &str) -> Result<()> + Send + Sync + Copy + 'static,
|
|
|
|
|
S: std::fmt::Write + Send + 'static,
|
|
|
|
|
{
|
|
|
|
|
Box::new(move |data| call(fun, &mut *out.lock().expect("locked"), &data))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn call<F, S>(fun: F, out: &mut S, data: &Data<'_>)
|
|
|
|
|
where
|
|
|
|
|
F: Fn(&mut S, &Level, &str, &str) -> Result<()>,
|
|
|
|
|
S: std::fmt::Write,
|
|
|
|
|
{
|
|
|
|
|
fun(out, &data.level(), data.span_name(), data.message()).expect("log line appended");
|
2024-06-11 01:26:31 +00:00
|
|
|
}
|