Type Definition charlie_buffalo::Dropper[][src]

type Dropper = Option<Arc<Mutex<dyn Fn(&Logger) + Send + 'static>>>;
Expand description

A function (or closure) called when logger is freed from memory.

Inside this function, you can do some actions like by example :

  • send a last log to save that the program is closed (if logger is effectively dropped at the end of the program)
  • display a message to user to say where are the logs (in case of you save it in file(s) in Dispatcher)

It is optional to use in logger, because maybe you don’t need to do something when logger is freed.

It should be safe to use in concurrent context.

Creation

You can create it with an helper :

let dropper: charlie_buffalo::Dropper =
    charlie_buffalo::new_dropper(Box::new(|_logger: &charlie_buffalo::Logger| {
        println!("The logger is now freed from memory");
    }));

Or you can create it manually :

let dropper: charlie_buffalo::Dropper =
    Some(std::sync::Arc::new(std::sync::Mutex::new(|_logger: &charlie_buffalo::Logger| {
        println!("The logger is now freed from memory");
    })));

Example

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

See also