slog-rs / slog

Structured, contextual, extensible, composable logging for Rust
https://slog.rs/
Apache License 2.0
1.58k stars 95 forks source link

Add `ErrorRef` wrapper #327

Closed demurgos closed 10 months ago

demurgos commented 11 months ago

This commit adds the ErrorRef wrapper type. It enables to log error by reference, without moving ownership. It means that it is the non-owning counterpart of ErrorValue.

Logging error references is an important use case for transparent logging middlewares. With this wrapper type, you can log the error and still pass it up the call stack.

Such a wrapper type could already easily be implemented in user applications, but having it as part of Slog should help ergonomics. This also enables further improvements by integrating it with the Slog macros.

Closes slog-rs/slog#288

Make sure to:

demurgos commented 11 months ago

Unfortunately this does not support dyn Error. I'll see if I can find something to help with it.

Techcable commented 10 months ago

Thank you! Sorry for the delayed review.

I will either open an issue or add a test for supporting dyn Error.