[][src]Function samp::plugin::logger

pub fn logger() -> Dispatch

Get a fern Dispatch and disable auto installing logger.

Example

This example deliberately fails to compile
use samp::initialize_plugin;
use samp::prelude::*;
 
use std::fs::OpenOptions;

struct MyPlugin;

impl SampPlugin for MyPlugin {}

initialize_plugin!({
    samp::plugin::enable_process_tick();
     
    // get a default samp logger (uses samp logprintf).
    let samp_logger = samp::plugin::logger()
        .level(log::LevelFilter::Warn); // logging only warn and error messages

    let log_file = fern::log_file("myplugin.log").expect("Something wrong!");

    // log trace and debug messages in an another file
    let trace_level = fern::Dispatch::new()
        .level(log::LevelFilter::Trace) // write ALL types of logs
        .chain(log_file);

    let _ = fern::Dispatch::new()
        .format(|callback, message, record| {
            // all messages will be formated like
            // [MyPlugin][ERROR]: something (error!("something"))
            // [MyPlugin][INFO]: some info (info!("some info"))
            callback.finish(format_args!("[MyPlugin][{}]: {}", record.level(), message))
        })
        .chain(samp_logger)
        .chain(trace_level)
        .apply();
 
    return MyPlugin;
});