forked from etcd-io/etcd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.go
116 lines (96 loc) · 2.58 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package raft
import (
"log"
"os"
)
//------------------------------------------------------------------------------
//
// Variables
//
//------------------------------------------------------------------------------
const (
Debug = 1
Trace = 2
)
var logLevel int = 0
var logger *log.Logger
func init() {
logger = log.New(os.Stdout, "[raft]", log.Lmicroseconds)
}
//------------------------------------------------------------------------------
//
// Functions
//
//------------------------------------------------------------------------------
func LogLevel() int {
return logLevel
}
func SetLogLevel(level int) {
logLevel = level
}
//--------------------------------------
// Warnings
//--------------------------------------
// Prints to the standard logger. Arguments are handled in the manner of
// fmt.Print.
func warn(v ...interface{}) {
logger.Print(v...)
}
// Prints to the standard logger. Arguments are handled in the manner of
// fmt.Printf.
func warnf(format string, v ...interface{}) {
logger.Printf(format, v...)
}
// Prints to the standard logger. Arguments are handled in the manner of
// fmt.Println.
func warnln(v ...interface{}) {
logger.Println(v...)
}
//--------------------------------------
// Basic debugging
//--------------------------------------
// Prints to the standard logger if debug mode is enabled. Arguments
// are handled in the manner of fmt.Print.
func debug(v ...interface{}) {
if logLevel >= Debug {
logger.Print(v...)
}
}
// Prints to the standard logger if debug mode is enabled. Arguments
// are handled in the manner of fmt.Printf.
func debugf(format string, v ...interface{}) {
if logLevel >= Debug {
logger.Printf(format, v...)
}
}
// Prints to the standard logger if debug mode is enabled. Arguments
// are handled in the manner of fmt.Println.
func debugln(v ...interface{}) {
if logLevel >= Debug {
logger.Println(v...)
}
}
//--------------------------------------
// Trace-level debugging
//--------------------------------------
// Prints to the standard logger if trace debugging is enabled. Arguments
// are handled in the manner of fmt.Print.
func trace(v ...interface{}) {
if logLevel >= Trace {
logger.Print(v...)
}
}
// Prints to the standard logger if trace debugging is enabled. Arguments
// are handled in the manner of fmt.Printf.
func tracef(format string, v ...interface{}) {
if logLevel >= Trace {
logger.Printf(format, v...)
}
}
// Prints to the standard logger if trace debugging is enabled. Arguments
// are handled in the manner of debugln.
func traceln(v ...interface{}) {
if logLevel >= Trace {
logger.Println(v...)
}
}