-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.go
48 lines (40 loc) · 986 Bytes
/
logger.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
package api
import (
"log"
"os"
)
type logLevel int
const (
// Debug log level
Debug logLevel = 0
// Info log level
Info logLevel = 1
// Warning log level
Warning logLevel = 5
// NoLogs disable logs completely
NoLogs logLevel = 9
)
var (
// LogLevel controls the global logging for the API calls.
LogLevel logLevel = Warning
// logger is the internal package logger.
logger = log.New(os.Stderr, "[minetools.api] ", log.Ldate|log.Ltime)
)
// Debugf logs the provided message if debug level is enabled
func Debugf(m string, args ...interface{}) {
if LogLevel <= Debug {
logger.Printf("DEBUG: "+m, args...)
}
}
// Infof logs the provided message if debug level is enabled
func Infof(m string, args ...interface{}) {
if LogLevel <= Info {
logger.Printf("INFO: "+m, args...)
}
}
// Warningf logs the provided message if debug level is enabled
func Warningf(m string, args ...interface{}) {
if LogLevel <= Warning {
logger.Printf("WARNING: "+m, args...)
}
}