-
Notifications
You must be signed in to change notification settings - Fork 509
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
new feature: Provide more ways to format the error in LoggingLayer
#4918
Comments
Maybe we can introduce something like opendal/core/src/layers/retry.rs Lines 236 to 265 in 5e735cc
Users can control their own way for errors, or maybe further, the whole log event. |
Makes sense to me. |
Let's make it open to track the progress of this feature. @evenyag do you have interest to implement this? |
@Xuanwo Oh, sorry. I found people can do this via the
Sure. I'm not sure what the "interceptor" should be.
|
Yes, my current idea is make it a part of
I wish to have an trait LoggingInterceptor {
fn log(&self, scheme: Scheme, operation: &'static str, path: &str, message: &str, err: Option<&Error>);
} The default behaivor will be like: struct DefaultLoggingInterceptor;
impl LoggingInterceptor for DefaultLoggingInterceptor {
fn log(&self, scheme: Scheme, operation: &'static str, path: &str, message: &str, err: Option<&Error>) {
// We can decide level based on `operation` and `err`.
let lvl = xxx;
if err.is_none {
log!(
target: LOGGING_TARGET,
lvl,
"service={scheme} operation={operation} path={path} -> {message}",
)
} else {
// print with error
}
}
} Some other change may also needed to make it work. We might can remove What do you think? I believe this design will make this layer more useful to play with other logging systems. |
Can we define a pub struct Record<'a> {
scheme: Scheme,
operation: &'static str,
path: &'a str,
message: &'a str,
err: Option<&'a Error>,
}
impl<'a> Record<'a> {
fn scheme(&self) -> Scheme {}
// ...
} What's more, should we pass the |
Add a new struct means we need to expose another new API along with many
We have |
Got it. I'll implement a prototype first. If I encounter any problems, I'll come back here. |
#4961 It should be ready for review. |
Feature Description
The logging layer provides a flag
backtrace_output
to control how the layer formats the error, mainly for displaying the backtrace.opendal/core/src/layers/logging.rs
Lines 188 to 200 in 5e735cc
By default, the layer formats the error using the
Display
trait. Even if we enable thebacktrace_output
flag, the layer may still useDisplay
if the error kind isn't unexpected.Sometimes, printing the
Error
in debug format is helpful because the display format may lack some information for debugging. The layer could add a flag to control how to format the error. e.g.debug_format_error
format_error()
and use that callback to format the error (This might conflict withbacktrace_output
)Problem and Solution
The main issue is that reqwest no longer prints the source error in its
Display
implementation. It only prints the source inDebug
. See: seanmonstar/reqwest#2199So we can't get the source error while opendal's HTTP client returns an error opendal's error also uses
Display
to format the source error.Here is an error log we captured:
The root cause of the error while sending the request is missing. It's quite painful to further diagnose the problem.
Alternative Solution:
Additional Context
No response
Are you willing to contribute to the development of this feature?
The text was updated successfully, but these errors were encountered: