WIP: Add an error field to Record #378

Closed
KodrAus wants to merge 1 commit from feat/record-error into master
KodrAus commented 2020-01-30 18:41:52 -06:00 (Migrated from github.com)

For #357

Adds a dyn Error + 'static field to Record so that concrete errors can be associated with a log event. I'd thought about adding a Send requirement, but decided against it because Record already isn't Send, there are error types out there folks might want to log that aren't Send, and since you can downcast errors if your app needs to send log records to other threads you could use that to downcast and build your own sendable record type.

r? @sfackler

Future extension

We could extend the macro to allow something like this in caller code:

let o = do_some_work().map_err(|e| {
    error!(source: &e, target: "some target", "I tried so hard, and got so far");
    e
})?;

Macro support could be added in a fairly naive way to the log macros, or we could take another stab at a tt muncher to support arbitrary special fields before the arguments.

For #357 Adds a `dyn Error + 'static` field to `Record` so that concrete errors can be associated with a log event. I'd thought about adding a `Send` requirement, but decided against it because `Record` already isn't `Send`, there are error types out there folks might want to log that aren't `Send`, and since you can downcast errors if your app needs to send log records to other threads you could use that to downcast and build your own sendable record type. r? @sfackler # Future extension We could extend the macro to allow something like this in caller code: ```rust let o = do_some_work().map_err(|e| { error!(source: &e, target: "some target", "I tried so hard, and got so far"); e })?; ``` Macro support could be added in a fairly naive way to the log macros, or we could take another stab at a tt muncher to support arbitrary special fields before the arguments.
sfackler (Migrated from github.com) reviewed 2020-01-30 19:00:00 -06:00
@ -819,3 +827,4 @@
/// The structued key-value pairs associated with the message.
#[cfg(feature = "kv_unstable")]
#[inline]
sfackler (Migrated from github.com) commented 2020-01-30 18:59:59 -06:00

This should mention it requires the std feature.

This should mention it requires the std feature.
sfackler (Migrated from github.com) reviewed 2020-01-30 19:00:08 -06:00
sfackler (Migrated from github.com) commented 2020-01-30 19:00:07 -06:00

Same here

Same here
sfackler commented 2020-01-30 19:01:43 -06:00 (Migrated from github.com)

Seems reasonable to me to not have a Send bound - even if the fmt::Arguments field wasn't also there you can't really ship a Record around since the error is just borrowed.

I do think we should figure out what the macro change looks like before cutting a release with this, though.

Seems reasonable to me to not have a Send bound - even if the fmt::Arguments field wasn't also there you can't really ship a Record around since the error is just borrowed. I do think we should figure out what the macro change looks like before cutting a release with this, though.
KodrAus commented 2020-01-30 20:36:40 -06:00 (Migrated from github.com)

I do think we should figure out what the macro change looks like before cutting a release with this, though.

Sure 👍 I might leave this PR sitting open then and switch over to #357 where we can work out how we want the macro to look. I don't think it'll be as risky to change the macros following the same scheme as target as the kv support was, because we're not messing with the token soup that gets forwarded to format_args.

> I do think we should figure out what the macro change looks like before cutting a release with this, though. Sure :+1: I might leave this PR sitting open then and switch over to #357 where we can work out how we want the macro to look. I don't think it'll be as risky to change the macros following the same scheme as `target` as the kv support was, because we're not messing with the token soup that gets forwarded to `format_args`.
KodrAus commented 2021-03-18 18:46:35 -05:00 (Migrated from github.com)

This has fallen pretty out of date now so I'll close it and revisit in the future.

This has fallen pretty out of date now so I'll close it and revisit in the future.

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-rust-lang/log!378
No description provided.