aboutsummaryrefslogtreecommitdiff
path: root/nexgb/log.go
blob: eaaa57e8ffb39d0837a85808f9d6763203842b3f (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package xgb

import (
	"log"
	"os"
)

// Log controls whether XGB emits errors to stderr. By default, it is enabled.
var PrintLog = true

// log is a wrapper around a log.PrintLogger so we can control whether it should
// output anything.
type xgblog struct {
	*log.Logger
}

func newLogger() xgblog {
	return xgblog{log.New(os.Stderr, "XGB: ", log.Lshortfile)}
}

func (lg xgblog) Print(v ...interface{}) {
	if PrintLog {
		lg.Logger.Print(v...)
	}
}

func (lg xgblog) Printf(format string, v ...interface{}) {
	if PrintLog {
		lg.Logger.Printf(format, v...)
	}
}

func (lg xgblog) Println(v ...interface{}) {
	if PrintLog {
		lg.Logger.Println(v...)
	}
}

func (lg xgblog) Fatal(v ...interface{}) {
	if PrintLog {
		lg.Logger.Fatal(v...)
	} else {
		os.Exit(1)
	}
}

func (lg xgblog) Fatalf(format string, v ...interface{}) {
	if PrintLog {
		lg.Logger.Fatalf(format, v...)
	} else {
		os.Exit(1)
	}
}

func (lg xgblog) Fatalln(v ...interface{}) {
	if PrintLog {
		lg.Logger.Fatalln(v...)
	} else {
		os.Exit(1)
	}
}

func (lg xgblog) Panic(v ...interface{}) {
	if PrintLog {
		lg.Logger.Panic(v...)
	} else {
		panic("")
	}
}

func (lg xgblog) Panicf(format string, v ...interface{}) {
	if PrintLog {
		lg.Logger.Panicf(format, v...)
	} else {
		panic("")
	}
}

func (lg xgblog) Panicln(v ...interface{}) {
	if PrintLog {
		lg.Logger.Panicln(v...)
	} else {
		panic("")
	}
}