-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
logger.go
71 lines (58 loc) · 1.9 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package queue
import (
"fmt"
"log"
"os"
)
// Logger interface is used throughout gorush
type Logger interface {
Infof(format string, args ...interface{})
Errorf(format string, args ...interface{})
Fatalf(format string, args ...interface{})
Info(args ...interface{})
Error(args ...interface{})
Fatal(args ...interface{})
}
// NewLogger for simple logger.
func NewLogger() Logger {
return defaultLogger{
infoLogger: log.New(os.Stderr, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile),
errorLogger: log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile),
fatalLogger: log.New(os.Stderr, "FATAL: ", log.Ldate|log.Ltime|log.Lshortfile),
}
}
type defaultLogger struct {
infoLogger *log.Logger
errorLogger *log.Logger
fatalLogger *log.Logger
}
func (l defaultLogger) Infof(format string, args ...interface{}) {
l.infoLogger.Printf(format, args...)
}
func (l defaultLogger) Errorf(format string, args ...interface{}) {
l.errorLogger.Printf(format, args...)
}
func (l defaultLogger) Fatalf(format string, args ...interface{}) {
l.fatalLogger.Fatalf(format, args...)
}
func (l defaultLogger) Info(args ...interface{}) {
l.infoLogger.Println(fmt.Sprint(args...))
}
func (l defaultLogger) Error(args ...interface{}) {
l.errorLogger.Println(fmt.Sprint(args...))
}
func (l defaultLogger) Fatal(args ...interface{}) {
l.fatalLogger.Println(fmt.Sprint(args...))
}
// NewEmptyLogger for simple logger.
func NewEmptyLogger() Logger {
return emptyLogger{}
}
// EmptyLogger no meesgae logger
type emptyLogger struct{}
func (l emptyLogger) Infof(format string, args ...interface{}) {}
func (l emptyLogger) Errorf(format string, args ...interface{}) {}
func (l emptyLogger) Fatalf(format string, args ...interface{}) {}
func (l emptyLogger) Info(args ...interface{}) {}
func (l emptyLogger) Error(args ...interface{}) {}
func (l emptyLogger) Fatal(args ...interface{}) {}