forked from jasonmf/wowlua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
40 lines (33 loc) · 898 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
package wowlua
import "log"
const (
// LogLevelDebug will log debug messages
LogLevelDebug = iota
// LogLevelErrors will output errors-only
LogLevelErrors
)
var (
logger Logger = DefaultLogger(LogLevelErrors)
)
// A Logger has a debug and error logging function
type Logger interface {
Debugf(tmpl string, v ...interface{})
Errorf(tmpl string, v ...interface{})
}
// DefaultLogger is a wrapper around the log package that conditionally logs
// based on its log level
type DefaultLogger int
// Debugf outputs a debug message if logging is set to LogLevelDebug
func (level DefaultLogger) Debugf(tmpl string, v ...interface{}) {
if level >= LogLevelDebug {
return
}
log.Printf("DEBUG: "+tmpl, v...)
}
// Errorf outputs and error message
func (level DefaultLogger) Errorf(tmpl string, v ...interface{}) {
if level >= LogLevelErrors {
return
}
log.Printf("ERROR: "+tmpl, v...)
}