InitBuilder

Struct InitBuilder 

Source
pub struct InitBuilder { /* private fields */ }
Expand description

InitBuilder is used to init ezlog

Implementations§

Source§

impl InitBuilder

Source

pub fn new() -> Self

Source

pub fn debug(self, debug: bool) -> Self

set debug mode

§Example
ezlog::InitBuilder::new()
    .debug(true)
    .init();
Source

pub fn with_event_listener(self, listener: &'static dyn EventListener) -> Self

add a listener to handle all events

§Example
use ezlog::Event;
use ezlog::LogError;

struct MyEventListener;

impl ezlog::EventListener for MyEventListener {
    fn on_event(&self, event: Event, desc: &str) {
        println!("event: {:?}, desc: {}", event, desc);
    }

    fn on_error_event(&self, event: Event, desc: &str, err: &LogError) {
        println!("event: {:?}, desc: {}, err: {}", event, desc, err);
    }
}
static LISTENER: MyEventListener = MyEventListener{};
ezlog::InitBuilder::new()
    .with_event_listener(&LISTENER)
    .init();
Source

pub fn with_layer(self, layer: Box<dyn MsgHandler>) -> Self

add a layer to handle all operations

§Example
use ezlog::MsgHandler;
struct MyLayer;

impl MyLayer {
    pub fn new() -> Self {
        Self {}
    }
}

impl ezlog::MsgHandler for MyLayer {
    fn handle(&self, msg: &ezlog::EZMsg) {
        println!("{:?}", msg);
    }
}

ezlog::InitBuilder::new()
    .with_layer(Box::new(MyLayer::new()))
    .init();
Source

pub fn with_request_callback_fn( self, on_success: fn(&str, &str, &[&str]), on_fail: fn(&str, &str, &str), ) -> Self

add a callback to receive log file path request result

§Example
let on_success : fn(&str, &str, &[&str]) = |name, date, logs| {
    println!("on_success: name: {}, desc: {}, tags: {:?}", name, date, logs);
};

let on_fail : fn(&str, &str, &str) = |name, date, err| {
    println!("on_fail: name: {}, desc: {}, err: {}", name, date, err);
};
ezlog::InitBuilder::new()
    .with_request_callback_fn(on_success, on_fail)
    .init();
Source

pub fn with_request_callback( self, callback: impl EZLogCallback + 'static, ) -> Self

add a callback to receive log file path request result

§Example
use ezlog::EZLogCallback;

struct MyCallback {}

impl EZLogCallback for MyCallback {
   fn on_fetch_success(&self, name: &str, date: &str, logs: &[&str]) {
       println!("on_success: name: {}, desc: {}, tags: {:?}", name, date, logs);
   }

   fn on_fetch_fail(&self, name: &str, date: &str, err: &str) {
       println!("on_fail: name: {}, desc: {}, err: {}", name, date, err);
   }
}

let callback: MyCallback = MyCallback {  };
ezlog::InitBuilder::new()
    .with_request_callback(callback)
    .init();
Source

pub fn with_layer_fn(self, layer: fn(&EZMsg)) -> Self

add a layer to handle all operations

§Example
ezlog::InitBuilder::new()
    .with_layer_fn(|msg| println!("{:?}", msg))
    .init();
Source

pub fn with_formatter(self, formatter: Box<dyn Formatter>) -> Self

set a formatter to format log record

§Example
use ezlog::Formatter;
use ezlog::EZRecord;
struct MyFormatter;
impl Formatter for MyFormatter {
   fn format(&self, msg: &EZRecord) -> std::result::Result<Vec<u8>, ezlog::LogError> {
      Ok(format!("{:?}", msg).into_bytes())
  }
}
ezlog::InitBuilder::new()
   .with_formatter(Box::new(MyFormatter))
   .init();
Source

pub fn with_formatter_fn(self, op: fn(&EZRecord) -> Vec<u8>) -> Self

set a formatter to format log record

§Example
ezlog::InitBuilder::new()
   .with_formatter_fn(|msg| format!("{:?}", msg).into_bytes())
   .init();
Source

pub fn init(self) -> EZLog

real init ezlog

Trait Implementations§

Source§

impl Default for InitBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Same for T

Source§

type Output = T

Should always be Self
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.