Debian Codegraph @

fs/fstestutil/debug.go

raw symbols SCIP
1 package fstestutil
2
3 import (
4 "flag"
5 "log"
6 "strconv"
7
8 "github.com/jacobsa/bazilfuse"
9 )
10
11 type flagDebug bool
12
13 var debug flagDebug
14
15 var _ = flag.Value(&debug)
16
17 func (f *flagDebug) IsBoolFlag() bool {
18 return true
19 }
20
21 func nop(msg interface{}) {}
22
23 func (f *flagDebug) Set(s string) error {
24 v, err := strconv.ParseBool(s)
25 if err != nil {
26 return err
27 }
28 *f = flagDebug(v)
29 if v {
30 fuse.Debug = logMsg
31 } else {
32 fuse.Debug = nop
33 }
34 return nil
35 }
36
37 func (f *flagDebug) String() string {
38 return strconv.FormatBool(bool(*f))
39 }
40
41 func logMsg(msg interface{}) {
42 log.Printf("FUSE: %s\n", msg)
43 }
44
45 func init() {
46 flag.Var(&debug, "fuse.debug", "log FUSE processing details")
47 }
48
49 // DebugByDefault changes the default of the `-fuse.debug` flag to
50 // true.
51 //
52 // This package registers a command line flag `-fuse.debug` and when
53 // run with that flag (and activated inside the tests), logs FUSE
54 // debug messages.
55 //
56 // This is disabled by default, as most callers probably won't care
57 // about FUSE details. Use DebugByDefault for tests where you'd
58 // normally be passing `-fuse.debug` all the time anyway.
59 //
60 // Call from an init function.
61 func DebugByDefault() {
62 f := flag.Lookup("fuse.debug")
63 f.DefValue = "true"
64 f.Value.Set(f.DefValue)
65 }