github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/libfuse/debug.go (about) 1 // Copyright 2016 Keybase Inc. All rights reserved. 2 // Use of this source code is governed by a BSD 3 // license that can be found in the LICENSE file. 4 // 5 //go:build !windows 6 // +build !windows 7 8 package libfuse 9 10 import ( 11 "fmt" 12 "regexp" 13 14 "github.com/keybase/client/go/libkb" 15 "github.com/keybase/client/go/logger" 16 ) 17 18 var statfsOrAccessRegexp = regexp.MustCompile(`^(<-|->).* (Statfs|Access)`) 19 20 // MakeFuseDebugFn returns a function that logs its argument to the 21 // given log, suitable to assign to fuse.Debug. 22 func MakeFuseDebugFn( 23 log logger.Logger, superVerbose bool) func(msg interface{}) { 24 return func(msg interface{}) { 25 str := fmt.Sprintf("%s", msg) 26 // If superVerbose is not set, filter out Statfs and 27 // Access messages, since they're spammy on OS X. 28 // 29 // Ideally, bazil would let us filter this better, and 30 // also pass in the ctx. 31 if !superVerbose && statfsOrAccessRegexp.MatchString(str) { 32 return 33 } 34 log.Debug("%s", str) 35 } 36 } 37 38 // MakeFuseVDebugFn returns a function that logs its argument to the 39 // given vlog at level 1, suitable to assign to fuse.Debug. 40 func MakeFuseVDebugFn( 41 vlog *libkb.VDebugLog, superVerbose bool) func(msg interface{}) { 42 return func(msg interface{}) { 43 str := fmt.Sprintf("%s", msg) 44 // If superVerbose is not set, filter out Statfs and 45 // Access messages, since they're spammy on OS X. 46 // 47 // Ideally, bazil would let us filter this better, and 48 // also pass in the ctx. 49 if !superVerbose && statfsOrAccessRegexp.MatchString(str) { 50 return 51 } 52 vlog.Log(libkb.VLog1, "%s", str) 53 } 54 }