2 releases

0.1.1 Feb 23, 2025
0.1.0 Feb 23, 2025

#455 in Debugging

Download history 234/week @ 2025-02-19 78/week @ 2025-02-26 9/week @ 2025-03-05

321 downloads per month

MIT license

4KB

result_logger

Rust crate to ease the logging of error results.

Just call the provided log funtions on Results and if its an error it gets logged by your logging implementation.

Available functions

Usage

fn calling_func() -> Result<(), String> {
    failing_func().error()?;
    
    // Do something
    
    Ok(())
}

fn failing_func() -> Result<(), String> {
    Err("This is an error".to_string())
}

-> This will log the error message "This is an error" with the log level Error.

License

This project is licensed under the MIT License. Feel free to contribute and modify as per the guidelines outlined in the license agreement.


lib.rs:

A utility crate for enhancing Result<T, E> with logging capabilities.

This crate provides the ResultLogging trait, which extends Result<T, E> with methods to log errors at different log levels using the log crate.

Example Usage

use log::{LevelFilter, info};
use simple_logger::SimpleLogger;
use result_logger::ResultLogger;

fn example_function() -> Result<(), &'static str> {
    Err("Something went wrong!")
}

fn main() {
    SimpleLogger::new().init().unwrap();
    let _ = example_function().error(); // Logs the error message at the error level
}

Dependencies

~86KB