pub struct LogFormat { /* private fields */ }Expand description
Custom formatter which adds into a log sink
Implementations§
Source§impl LogFormat
impl LogFormat
Sourcepub fn new(time_fmt: &str, format_fn: FormatFunc) -> Self
pub fn new(time_fmt: &str, format_fn: FormatFunc) -> Self
§Arguments
time_fmt: refer to chrono::format::strftime.
format_fn: Since std::fmt only support compile time format, you have to write a static function to format the log line
§Example
use captains_log::{LogRawFile, LogFormat, FormatRecord};
fn format_f(r: FormatRecord) -> String {
let time = r.time();
let level = r.level();
let msg = r.msg();
let req_id = r.key("req_id");
format!("[{time}][{level}] {msg}{req_id}\n").to_string()
}
let log_format = LogFormat::new("%Y-%m-%d %H:%M:%S%.6f", format_f);
let log_sink = LogRawFile::new("/tmp", "test.log", log::Level::Info, log_format);Trait Implementations§
Auto Trait Implementations§
impl Freeze for LogFormat
impl RefUnwindSafe for LogFormat
impl Send for LogFormat
impl Sync for LogFormat
impl Unpin for LogFormat
impl UnwindSafe for LogFormat
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more