evenyag commented on code in PR #4986:
URL: https://github.com/apache/opendal/pull/4986#discussion_r1716530358
##########
core/src/layers/logging.rs:
##########
@@ -210,81 +157,97 @@ pub trait LoggingInterceptor: Debug + Send + Sync +
'static {
/// could perform unexpectedly slow.
fn log(
&self,
- scheme: Scheme,
+ info: &AccessorInfo,
operation: Operation,
- context: &str,
+ context: &[(&str, &str)],
message: &str,
err: Option<&Error>,
);
}
/// The DefaultLoggingInterceptor will log the message by the standard logging
macro.
-#[derive(Debug)]
+#[derive(Debug, Copy, Clone, Default)]
pub struct DefaultLoggingInterceptor;
impl LoggingInterceptor for DefaultLoggingInterceptor {
+ #[inline]
fn log(
&self,
- scheme: Scheme,
+ info: &AccessorInfo,
operation: Operation,
- context: &str,
+ context: &[(&str, &str)],
message: &str,
err: Option<&Error>,
) {
- let Some(err) = err else {
- let lvl = self.operation_level(operation);
+ if let Some(err) = err {
+ // Print error if it's unexpected, otherwise in warn.
+ let lvl = if err.kind() == ErrorKind::Unexpected {
+ Level::Error
+ } else {
+ Level::Warn
+ };
+
log!(
target: LOGGING_TARGET,
lvl,
- "service={} operation={} {} -> {}",
- scheme,
- operation,
- context,
- message,
+ "service={} name={} {}: {operation} {message} {}",
+ info.scheme(),
+ info.name(),
+ format_args!(
+ "{}",
+ context.iter().enumerate().map(|(i, (k, v))| {
+ if i > 0 {
+ format!(" {}={}", k, v)
+ } else {
+ format!("{}={}", k, v)
+ }
+ }).collect::<String>()
Review Comment:
Looks like we need more allocations than before. One string for each
key-value pair and the collected string.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]