-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
57 lines (48 loc) · 857 Bytes
/
log.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
54
55
56
57
package main
import (
"flag"
"fmt"
"log"
"os"
)
var shouldLog = false
func init() {
flag.BoolVar(&shouldLog, "log", false, "Log all actions")
log.SetOutput(os.Stderr)
}
func info(msg string) {
if !shouldLog {
return
}
log.Println("[info]", msg)
}
func infof(fmtString string, args ...interface{}) {
if !shouldLog {
return
}
log.Println(fmt.Sprintf("[info] "+fmtString, args...))
}
func debug(msg string) {
if !shouldLog {
return
}
log.Println("[debug]", msg)
}
func debugf(fmtString string, args ...interface{}) {
if !shouldLog {
return
}
log.Println(fmt.Sprintf("[debug] "+fmtString, args...))
}
func trace(msg string) {
if !shouldLog {
return
}
log.Println("[trace]", msg)
}
func tracef(fmtString string, args ...interface{}) {
if !shouldLog {
return
}
log.Println(fmt.Sprintf("[info] "+fmtString, args...))
}