tklog

Struct AttrFormat

Source
pub struct AttrFormat { /* private fields */ }

Implementations§

Source§

impl AttrFormat

Source

pub fn new() -> AttrFormat

Source

pub fn set_level_fmt<F>(&mut self, levelfmt: F)
where F: Fn(LEVEL) -> String + Send + Sync + 'static,

§Exmaple
set_level_fmt(|level| {
    let s = match level {
        LEVEL::Trace => "[T]",
        LEVEL::Debug => "[D]",
        LEVEL::Info => "[I]",
        LEVEL::Warn => "[W]",
        LEVEL::Error => "[E]",
        LEVEL::Fatal => "[F]",
        LEVEL::Off => "",
    };
    s.to_string()
});
Source

pub fn set_time_fmt<F>(&mut self, timefmt: F)
where F: Fn() -> (String, String, String) + Send + Sync + 'static,

  • This function splits a date into three parts and returns a tuple (String, String, String).
  • You can customize the data for these three parts.
§Generally,
  • the first part is the date in the format %Y-%m-%d,
  • the second part is the time in the format %H:%M:%S,
  • and the third part is the fractional seconds, such as 6f.
§Example
set_time_fmt(|| {
    let now: DateTime<Local> = Local::now();
    (now.format("%Y-%m-%d").to_string(), now.format("%H:%M:%S").to_string(), ".6f".to_string())
});
Source

pub fn set_body_fmt<F>(&mut self, bodyfmt: F)
where F: Fn(LEVEL, String) -> String + Send + Sync + 'static,

§This function will support the reprocessing of log information
§Example
fmt.set_body_fmt(|level,body| {
    match level {
        LEVEL::Trace =>  format!("{}{}{}","\x1b[34m" ,body,"\x1b[0m") , //blue
        LEVEL::Debug => format!("{}{}{}","\x1b[36m" ,body,"\x1b[0m") , //cyan
        LEVEL::Info => format!("{}{}{}","\x1b[32m" ,body,"\x1b[0m") ,  //green
        LEVEL::Warn => format!("{}{}{}","\x1b[33m" ,body,"\x1b[0m") ,  //yellow
        LEVEL::Error => format!("{}{}{}","\x1b[31m" ,body,"\x1b[0m") , //red
        LEVEL::Fatal => format!("{}{}{}","\x1b[41m" ,body,"\x1b[0m") , //red-background
        LEVEL::Off => "".to_string(),
    }
});
Source

pub fn set_console_body_fmt<F>(&mut self, bodyfmt: F)
where F: Fn(LEVEL, String) -> String + Send + Sync + 'static,

§This function will support the reprocessing of log information
§Example
fmt.set_console_body_fmt(|level,body| {
    match level {
        LEVEL::Trace =>  format!("{}{}{}","\x1b[34m" ,body,"\x1b[0m") , //blue
        LEVEL::Debug => format!("{}{}{}","\x1b[36m" ,body,"\x1b[0m") , //cyan
        LEVEL::Info => format!("{}{}{}","\x1b[32m" ,body,"\x1b[0m") ,  //green
        LEVEL::Warn => format!("{}{}{}","\x1b[33m" ,body,"\x1b[0m") ,  //yellow
        LEVEL::Error => format!("{}{}{}","\x1b[31m" ,body,"\x1b[0m") , //red
        LEVEL::Fatal => format!("{}{}{}","\x1b[41m" ,body,"\x1b[0m") , //red-background
        LEVEL::Off => "".to_string(),
    }
});

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.