#error-logging #err #shorthand #methods #log-unwrap

log_err

Log error messages from Unwrap and Expect with log crate

4 stable releases

1.1.1 Apr 25, 2021
1.0.1 Apr 14, 2021
1.0.0 Apr 12, 2021

#2352 in Rust patterns

Download history 131/week @ 2025-07-27 116/week @ 2025-08-03 118/week @ 2025-08-10 123/week @ 2025-08-17 140/week @ 2025-08-24 180/week @ 2025-08-31 155/week @ 2025-09-07 161/week @ 2025-09-14 140/week @ 2025-09-21 150/week @ 2025-09-28 125/week @ 2025-10-05 137/week @ 2025-10-12 179/week @ 2025-10-19 137/week @ 2025-10-26 211/week @ 2025-11-02 148/week @ 2025-11-09

685 downloads per month
Used in 3 crates

Unlicense

7KB
65 lines

Crates.io License Docs

Log_Err

A small extension to the log crate, which provides two methods for core::result::Result<T, E> and core::option::Option<T>

log_except and log_unwrap, which invoke the log::error! macro (in case of Result::Err/Option::None) in addition to unwrapping/expecting the Result/Option.

Shorthand for:

something().map_err(|e| error!("{}: {:?}", msg, e)).expect(msg)

Example:

let mut file = File::create("foo.txt").log_expect("Error creating file");
# Error will be logged with the error! macro
[ERROR] Error creating file: Os { code: 2, kind: NotFound, message: "No such file or directory" }

# Main program panic'ing with same message
thread 'main' panicked at 'Error creating file: Os { code: 2, kind: NotFound, message: "No such file or directory" }', test.rs:4:48

Dependencies

~99KB