Xuanwo commented on code in PR #4986:
URL: https://github.com/apache/opendal/pull/4986#discussion_r1716555984


##########
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:
   Perhaps we could use a single string with calculated capacity to ensure only 
one allocation occurs. Or something better, we can implement a new type 
`LoggingContext(&[(&str, &str)])` and implement `Display` for it.
   
   Would you like to help implement it?



-- 
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]

Reply via email to