-
Notifications
You must be signed in to change notification settings - Fork 130
/
logging.go
56 lines (46 loc) · 1.14 KB
/
logging.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
package curl
import (
"log"
)
const (
_DEBUG = 10 * (iota + 1)
_INFO
_WARN
_ERROR
)
const _DEFAULT_LOG_LEVEL = _WARN
var log_level = _DEFAULT_LOG_LEVEL
// SetLogLevel changes the log level which determines the granularity of the
// messages that are logged. Available log levels are: "DEBUG", "INFO",
// "WARN", "ERROR" and "DEFAULT_LOG_LEVEL".
func SetLogLevel(levelName string) {
switch levelName {
case "DEBUG":
log_level = _DEBUG
case "INFO":
log_level = _INFO
case "WARN":
log_level = _WARN
case "ERROR":
log_level = _ERROR
case "DEFAULT_LOG_LEVEL":
log_level = _DEFAULT_LOG_LEVEL
}
}
func logf(limitLevel int, format string, args ...interface{}) {
if log_level <= limitLevel {
log.Printf(format, args...)
}
}
func debugf(format string, args ...interface{}) {
logf(_DEBUG, format, args...)
}
func infof(format string, args ...interface{}) {
logf(_INFO, format, args...)
}
func warnf(format string, args ...interface{}) {
logf(_WARN, format, args...)
}
func errorf(format string, args ...interface{}) {
logf(_ERROR, format, args...)
}