Commit 5711e18b authored by Aaron Jacobs's avatar Aaron Jacobs

Improved the readability of debug logging.

parents 348ed9e7 6450a1cb
...@@ -476,9 +476,9 @@ func (c *Connection) Reply(ctx context.Context, opErr error) { ...@@ -476,9 +476,9 @@ func (c *Connection) Reply(ctx context.Context, opErr error) {
// Debug logging // Debug logging
if c.debugLogger != nil { if c.debugLogger != nil {
if opErr == nil { if opErr == nil {
c.debugLog(fuseID, 1, "-> OK: %s", describeResponse(op)) c.debugLog(fuseID, 1, "-> OK")
} else { } else {
c.debugLog(fuseID, 1, "-> error: %v", opErr) c.debugLog(fuseID, 1, "-> Error: %q", opErr.Error())
} }
} }
......
...@@ -17,31 +17,55 @@ package fuse ...@@ -17,31 +17,55 @@ package fuse
import ( import (
"fmt" "fmt"
"reflect" "reflect"
"strings"
"github.com/jacobsa/fuse/fuseops"
) )
func describeRequest(op interface{}) (s string) { // Decide on the name of the given op.
// Handle special cases with custom formatting. func opName(op interface{}) string {
switch typed := op.(type) { // We expect all ops to be pointers.
case *interruptOp: t := reflect.TypeOf(op).Elem()
s = fmt.Sprintf("interruptOp(fuseid=0x%08x)", typed.FuseID)
return
}
// Strip the "Op" from "FooOp".
return strings.TrimSuffix(t.Name(), "Op")
}
func describeRequest(op interface{}) (s string) {
v := reflect.ValueOf(op).Elem() v := reflect.ValueOf(op).Elem()
t := v.Type()
// Find the inode number involved, if possible. // We will set up a comma-separated list of components.
var inodeDesc string var components []string
addComponent := func(format string, v ...interface{}) {
components = append(components, fmt.Sprintf(format, v...))
}
// Include an inode number, if available.
if f := v.FieldByName("Inode"); f.IsValid() { if f := v.FieldByName("Inode"); f.IsValid() {
inodeDesc = fmt.Sprintf("(inode=%v)", f.Interface()) addComponent("inode %v", f.Interface())
} }
// Use the type name. // Handle special cases.
s = fmt.Sprintf("%s%s", t.Name(), inodeDesc) switch typed := op.(type) {
case *interruptOp:
addComponent("fuseid 0x%08x", typed.FuseID)
return case *fuseops.ReadFileOp:
} addComponent("handle %d", typed.Handle)
addComponent("offset %d", typed.Offset)
addComponent("%d bytes", len(typed.Dst))
case *fuseops.WriteFileOp:
addComponent("handle %d", typed.Handle)
addComponent("offset %d", typed.Offset)
addComponent("%d bytes", len(typed.Data))
}
// Use just the name if there is no extra info.
if len(components) == 0 {
return opName(op)
}
func describeResponse(op interface{}) (s string) { // Otherwise, include the extra info.
return describeRequest(op) return fmt.Sprintf("%s (%s)", opName(op), strings.Join(components, ", "))
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment