-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry.go
107 lines (93 loc) · 1.96 KB
/
entry.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package logger
import "fmt"
// Entry provides unique interfaces on top of multiple logger backends.
// Entry also implements @Interface.
type Entry struct {
loggers []Interface
}
// NewEntry creates a new logger Entry
func NewEntry(loggers []Interface) *Entry {
return &Entry{
loggers: loggers,
}
}
// Debug ...
func (e *Entry) Debug(v ...interface{}) {
for _, l := range e.loggers {
l.Debug(v...)
}
}
// Debugf with format
func (e *Entry) Debugf(format string, v ...interface{}) {
for _, l := range e.loggers {
l.Debugf(format, v...)
}
}
// Info ...
func (e *Entry) Info(v ...interface{}) {
for _, l := range e.loggers {
l.Info(v...)
}
}
// Infof with format
func (e *Entry) Infof(format string, v ...interface{}) {
for _, l := range e.loggers {
l.Infof(format, v...)
}
}
// Warning ...
func (e *Entry) Warning(v ...interface{}) {
for _, l := range e.loggers {
l.Warning(v...)
}
}
// Warningf with format
func (e *Entry) Warningf(format string, v ...interface{}) {
for _, l := range e.loggers {
l.Warningf(format, v...)
}
}
// Error ...
func (e *Entry) Error(v ...interface{}) {
for _, l := range e.loggers {
l.Error(v...)
}
}
// Errorf with format
func (e *Entry) Errorf(format string, v ...interface{}) {
for _, l := range e.loggers {
l.Errorf(format, v...)
}
}
// Fatal error
func (e *Entry) Fatal(v ...interface{}) {
for _, l := range e.loggers {
l.Fatal(v...)
}
}
// Fatalf error
func (e *Entry) Fatalf(format string, v ...interface{}) {
for _, l := range e.loggers {
l.Fatalf(format, v...)
}
}
// Close logger
func (e *Entry) Close() error {
var errMsg string
for _, l := range e.loggers {
if closer, ok := l.(Closer); ok {
err := closer.Close()
if err != nil {
if errMsg == "" {
errMsg = fmt.Sprintf("logger: %s, err: %s", GetLoggerName(l), err)
} else {
errMsg = fmt.Sprintf("%s; logger: %s, err: %s", errMsg, GetLoggerName(l), err)
}
}
}
}
if errMsg != "" {
return fmt.Errorf(errMsg)
}
return nil
}