rustcursive

cursive-flexi-logger-view throwing unhandled error


After I start the application I got the error below and how it looks in the app

mintozzy@laptop:~/tmp/storytel-tui$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.50s
     Running `target/debug/storytel-tui`
[flexi_logger][ERRCODE::Time] flexi_logger has to work with UTC rather than with local time, caused by IndeterminateOffset
    See https://docs.rs/flexi_logger/latest/flexi_logger/error_info/index.html#time
[flexi_logger][ERRCODE::Write] writing log line failed, caused by Custom { kind: BrokenPipe, error: "cursive callback sink is closed!" }
    See https://docs.rs/flexi_logger/latest/flexi_logger/error_info/index.html#write

cursive log dialog

[dependencies]
reqwest = { version = "0.11.11", features = ["json", "blocking"] }
serde = { version = "1.0.139", features = ["derive"] }
serde_json = "1.0.82"
mpv = "0.2.3"
openssl = { version = "0.10.41" }
cursive = { version = "0.18" , default-features = false, features = ["crossterm-backend"]}
cursive-flexi-logger-view = "^0"
flexi_logger = "0.22.6"

I used the example code https://docs.rs/cursive-flexi-logger-view/latest/cursive_flexi_logger_view/#using-the-flexiloggerview screen is flickering, looks like logger printing below and breaking the UI.

what can be the reason ?


Solution

  • After cursive-flexi-logger-view failing I found that cursive has debug console. I think it is better solution because no need to add another dependency.

    To enable debug log added code below

    cursive::logger::init();
    match std::env::var("RUST_LOG").unwrap_or_else(|_| "info".to_string()).as_ref() {
        "trace" => log::set_max_level(LevelFilter::Trace),
        "debug" => log::set_max_level(LevelFilter::Debug),
        "info" => log::set_max_level(LevelFilter::Info),
        "warn" => log::set_max_level(LevelFilter::Warn),
        "error" => log::set_max_level(LevelFilter::Error),
        _ => log::set_max_level(LevelFilter::Off),
    }
    siv.add_global_callback('~', Cursive::toggle_debug_console);
    

    with this setup in UI I can enable debug console by typing ~ and it opens the debug window which has logged data in it. Below you can see how it looks

    debug console in cursive

    You can find full working code here