rosrust icon indicating copy to clipboard operation
rosrust copied to clipboard

Support ROSCONSOLE_FORMAT

Open lucasw opened this issue 3 years ago • 1 comments

I'm going to take this on myself to learn more about rust and rosrust.

http://wiki.ros.org/rosconsole#Console_Output_Formatting

This looks like the code to modify in rosrust/src/api/ros.rs:

    fn log_to_terminal(&self, level: i8, msg: &str, file: &str, line: u32) {
        use colored::{Color, Colorize};

        let format_string =
            |prefix, color| format!("[{} @ {}:{}]: {}", prefix, file, line, msg).color(color);

        match level {
            Log::DEBUG => println!("{}", format_string("DEBUG", Color::White)),
            Log::INFO => println!("{}", format_string("INFO", Color::White)),
            Log::WARN => eprintln!("{}", format_string("WARN", Color::Yellow)),
            Log::ERROR => eprintln!("{}", format_string("ERROR", Color::Red)),
            Log::FATAL => eprintln!("{}", format_string("FATAL", Color::Red)),
            _ => {}
        }
    }

Mine for example is:

[${severity}][${time} ${file}:${line} ${node}]: ${message}

It shouldn't be too hard to read the environmental variable and then convert it to a eprintln compatible format_string.

lucasw avatar Nov 21 '20 21:11 lucasw

This is mostly working in https://github.com/lucasw/rosrust/tree/rosconsole_format

lucasw avatar Nov 26 '20 15:11 lucasw