Improved the readability of debug logging.
commit
5711e18bd0
|
@ -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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
60
debug.go
60
debug.go
|
@ -17,31 +17,55 @@ package fuse
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/jacobsa/fuse/fuseops"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Decide on the name of the given op.
|
||||||
|
func opName(op interface{}) string {
|
||||||
|
// We expect all ops to be pointers.
|
||||||
|
t := reflect.TypeOf(op).Elem()
|
||||||
|
|
||||||
|
// Strip the "Op" from "FooOp".
|
||||||
|
return strings.TrimSuffix(t.Name(), "Op")
|
||||||
|
}
|
||||||
|
|
||||||
func describeRequest(op interface{}) (s string) {
|
func describeRequest(op interface{}) (s string) {
|
||||||
// Handle special cases with custom formatting.
|
v := reflect.ValueOf(op).Elem()
|
||||||
|
|
||||||
|
// We will set up a comma-separated list of components.
|
||||||
|
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() {
|
||||||
|
addComponent("inode %v", f.Interface())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle special cases.
|
||||||
switch typed := op.(type) {
|
switch typed := op.(type) {
|
||||||
case *interruptOp:
|
case *interruptOp:
|
||||||
s = fmt.Sprintf("interruptOp(fuseid=0x%08x)", typed.FuseID)
|
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))
|
||||||
}
|
}
|
||||||
|
|
||||||
v := reflect.ValueOf(op).Elem()
|
// Use just the name if there is no extra info.
|
||||||
t := v.Type()
|
if len(components) == 0 {
|
||||||
|
return opName(op)
|
||||||
// Find the inode number involved, if possible.
|
|
||||||
var inodeDesc string
|
|
||||||
if f := v.FieldByName("Inode"); f.IsValid() {
|
|
||||||
inodeDesc = fmt.Sprintf("(inode=%v)", f.Interface())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the type name.
|
// Otherwise, include the extra info.
|
||||||
s = fmt.Sprintf("%s%s", t.Name(), inodeDesc)
|
return fmt.Sprintf("%s (%s)", opName(op), strings.Join(components, ", "))
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func describeResponse(op interface{}) (s string) {
|
|
||||||
return describeRequest(op)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue