fn write_buffered(
    format_function: FormatFunction,
    now: &mut DeferredNow,
    record: &Record,
    w: &mut dyn Write,
) -> Result<(), std::io::Error> {
    let mut result: Result<(), std::io::Error> = Ok(());

    buffer_with(|tl_buf| match tl_buf.try_borrow_mut() {
        Ok(mut buffer) => {
            (format_function)(&mut *buffer, now, record)
                .unwrap_or_else(|e| write_err(ERR_FORMATTING, &e));
            buffer
                .write_all(b"\n")
                .unwrap_or_else(|e| write_err(ERR_FORMATTING, &e));

            result = w.write_all(&*buffer).map_err(|e| {
                write_err(ERR_WRITING, &e);
                e
            });

            buffer.clear();
        }
        Err(_e) => {
            // We arrive here in the rare cases of recursive logging
            // (e.g. log calls in Debug or Display implementations)
            // we print the inner calls, in chronological order, before finally the
            // outer most message is printed
            let mut tmp_buf = Vec::<u8>::with_capacity(200);
            (format_function)(&mut tmp_buf, now, record)
                .unwrap_or_else(|e| write_err(ERR_FORMATTING, &e));
            tmp_buf
                .write_all(b"\n")
                .unwrap_or_else(|e| write_err(ERR_FORMATTING, &e));

            result = w.write_all(&tmp_buf).map_err(|e| {
                write_err(ERR_WRITING, &e);
                e
            });
        }
    });
    result
}
// Use a thread-local buffer for writing to stderr
Use a thread-local buffer for writing to stderr
Use a thread - local buffer for writing to stderr
fn write_buffered(
    format_function: FormatFunction,
    now: &mut DeferredNow,
    record: &Record,
    w: &mut dyn Write,
) -> Result<(), std::io::Error> {
    let mut result: Result<(), std::io::Error> = Ok(());
    buffer_with(|tl_buf| match tl_buf.try_borrow_mut() {
        Ok(mut buffer) => {
            (format_function)(&mut *buffer, now, record)
                .unwrap_or_else(|e| write_err(ERR_FORMATTING, &e));
            buffer
                .write_all(b"\n")
                .unwrap_or_else(|e| write_err(ERR_FORMATTING, &e));
            result = w.write_all(&*buffer).map_err(|e| {
                write_err(ERR_WRITING, &e);
                e
            });
            buffer.clear();
        }
        Err(_e) => {
            // We arrive here in the rare cases of recursive logging
            // (e.g. log calls in Debug or Display implementations)
            // we print the inner calls, in chronological order, before finally the
            // outer most message is printed
            let mut tmp_buf = Vec::<u8>::with_capacity(200);
            (format_function)(&mut tmp_buf, now, record)
                .unwrap_or_else(|e| write_err(ERR_FORMATTING, &e));
            tmp_buf
                .write_all(b"\n")
                .unwrap_or_else(|e| write_err(ERR_FORMATTING, &e));
            result = w.write_all(&tmp_buf).map_err(|e| {
                write_err(ERR_WRITING, &e);
                e
            });
        }
    });
    result
}
fn write_buffered ( format_function : FormatFunction , now : & mut DeferredNow , record : & Record , w : & mut dyn Write , ) -> Result < ( ) , std :: io :: Error > { let mut result : Result < ( ) , std :: io :: Error > = Ok ( ( ) ) ; buffer_with ( | tl_buf | match tl_buf . try_borrow_mut ( ) { Ok ( mut buffer ) => { ( format_function ) ( & mut * buffer , now , record ) . unwrap_or_else ( | e | write_err ( ERR_FORMATTING , & e ) ) ; buffer . write_all ( b" \n " ) . unwrap_or_else ( | e | write_err ( ERR_FORMATTING , & e ) ) ; result = w . write_all ( & * buffer ) . map_err ( | e | { write_err ( ERR_WRITING , & e ) ; e } ) ; buffer . clear ( ) ; } Err ( _e ) => { // We arrive here in the rare cases of recursive logging // (e.g. log calls in Debug or Display implementations) // we print the inner calls, in chronological order, before finally the // outer most message is printed let mut tmp_buf = Vec :: < u8 > :: with_capacity ( 200 ) ; ( format_function ) ( & mut tmp_buf , now , record ) . unwrap_or_else ( | e | write_err ( ERR_FORMATTING , & e ) ) ; tmp_buf . write_all ( b" \n " ) . unwrap_or_else ( | e | write_err ( ERR_FORMATTING , & e ) ) ; result = w . write_all ( & tmp_buf ) . map_err ( | e | { write_err ( ERR_WRITING , & e ) ; e } ) ; } } ) ; result }
Use a thread-local buffer for writing to stderr
Use a thread - local buffer for writing to stderr
format_function
FormatFunction
now
&mut DeferredNow
record
&Record
w
&mut dyn Write
format_function
FormatFunction
now
&mut DeferredNow
record
&Record
w
&mut dyn Write