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