Type Definition charlie_buffalo::Dispatcher[][src]

type Dispatcher = Arc<Mutex<dyn FnMut(Log) + Send + 'static>>;
Expand description

A dispatcher is a function (or closure) called on each log received.

Inside this function, you can process the received log, like by example :

  • modify it (by cloning it then use this clone) to add date time
  • save it in a file
  • displaying it in stdout and/or stderr
  • send it to a web API through HTTP or TCP client call

It should be safe to use in concurrent context.

Creation

You can create it with an helper :

let dispatcher: charlie_buffalo::Dispatcher =
    charlie_buffalo::new_dispatcher(Box::new(|log: charlie_buffalo::Log| {
        println!("{}", log);
    }));

Or you can create it manually :

let dispatcher: charlie_buffalo::Dispatcher =
    std::sync::Arc::new(std::sync::Mutex::new(|log: charlie_buffalo::Log| {
        println!("{}", log);
    }));

Example

See an example in /examples/full_demo.rs in source repository.

See also

new_dispatcher