Function boxed_flexi_log_writer

Source
pub fn boxed_flexi_log_writer(siv: &Cursive) -> Box<dyn LogWriter>
Expand description

Creates a new LogWriter instance for the FlexiLoggerView. Use this to register a cursive log writer in flexi_logger.

Although, it is safe to create multiple cursive log writers, it may not be what you want. Each instance of a cursive log writer replicates the log messages in to FlexiLoggerView. When registering multiple cursive log writer instances, a single log messages will be duplicated by each log writer.

ยงRegistering the cursive log writer in flexi_logger

use cursive::{Cursive, CursiveExt};
use flexi_logger::Logger;

    // we need to initialize cursive first, as the cursive-logger-view
    // needs a cursive callback sink to notify cursive about screen refreshs
    // when a new log message arrives
    let mut siv = Cursive::default();

    Logger::try_with_env_or_str("trace")
        .expect("Could not create Logger from environment :(")
        .log_to_file_and_writer(
           flexi_logger::FileSpec::default()
                .directory("logs")
                .suppress_timestamp(),
            cursive_logger_view::boxed_flexi_log_writer(&siv)
        )
        .start()
        .expect("failed to initialize logger!");