forked from egirna/icap-client
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug.go
More file actions
55 lines (44 loc) · 1.01 KB
/
debug.go
File metadata and controls
55 lines (44 loc) · 1.01 KB
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
54
55
package icapclient
import (
"io"
"log"
"os"
"github.com/davecgh/go-spew/spew"
)
// the debug mode determiner & the writer to the write the debug output to
var (
DEBUG = false
debugWriter io.Writer
logger *log.Logger
)
const (
debugPrefix = "icap-client says: "
)
// SetDebugMode sets the debug mode for the entire package depending on the bool
func SetDebugMode(debug bool) {
DEBUG = debug
if DEBUG { // setting os.Stdout as the default debug writer if debug mode is enabled & also the debug prefix
debugWriter = os.Stdout
logger = log.New(debugWriter, debugPrefix, log.LstdFlags)
}
}
// SetDebugOutput sets writer to write the debug outputs (default: os.Stdout)
func SetDebugOutput(w io.Writer) {
debugWriter = w
logger.SetOutput(debugWriter)
}
func logDebug(a ...interface{}) {
if DEBUG {
logger.Println(a...)
}
}
func logfDebug(s string, a ...interface{}) {
if DEBUG {
logger.Printf(s, a...)
}
}
func dumpDebug(a ...interface{}) {
if DEBUG {
spew.Fdump(debugWriter, a...)
}
}