Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an error field to Record #378

Closed
wants to merge 1 commit into from

Conversation

KodrAus
Copy link
Contributor

@KodrAus KodrAus commented Jan 31, 2020

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.

@@ -816,6 +818,13 @@ impl<'a> Record<'a> {
self.line
}

/// The error associated with the message.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should mention it requires the std feature.

@@ -979,6 +992,14 @@ impl<'a> RecordBuilder<'a> {
self
}

/// Set [`error`](struct.Record.html#method.error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@sfackler
Copy link
Member

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
Copy link
Contributor Author

KodrAus commented Jan 31, 2020

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.

@KodrAus
Copy link
Contributor Author

KodrAus commented Mar 18, 2021

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

@KodrAus KodrAus closed this Mar 18, 2021
EFanZh pushed a commit to EFanZh/log that referenced this pull request Jul 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants