-
Notifications
You must be signed in to change notification settings - Fork 6
/
logger.go
47 lines (42 loc) · 1022 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
package main
import (
"io/ioutil"
"log"
"os"
)
type Logger struct {
Debug *log.Logger
Info *log.Logger
Warning *log.Logger
Error *log.Logger
}
var L *Logger
func init() {
L = &Logger{
log.New(ioutil.Discard, "[DEBUG]", log.Ldate|log.Ltime),
log.New(os.Stdout, "[INFO] ", log.Ldate|log.Ltime),
log.New(os.Stderr, "[WARN] ", log.Ldate|log.Ltime),
log.New(os.Stderr, "[ERR] ", log.Ldate|log.Ltime),
}
}
func (logger *Logger) Verbose(active bool) {
if active {
//TODO replace in golang 1.5
//logger.Debug.SetOutput(os.Stdout)
logger.Debug = log.New(os.Stdout, "[DEBUG]", log.Ldate|log.Ltime)
} else {
logger.Debug = log.New(ioutil.Discard, "[DEBUG]", log.Ldate|log.Ltime)
}
}
func (logger *Logger) DEBUG(v ...interface{}) {
logger.Debug.Println(v...)
}
func (logger *Logger) ERR(v ...interface{}) {
logger.Error.Println(v...)
}
func (logger *Logger) WARN(v ...interface{}) {
logger.Warning.Println(v...)
}
func (logger *Logger) INFO(v ...interface{}) {
logger.Info.Println(v...)
}