-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti.go
More file actions
80 lines (68 loc) · 1.38 KB
/
multi.go
File metadata and controls
80 lines (68 loc) · 1.38 KB
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
package redlog
import (
"fmt"
"strings"
)
const (
OMNI_FLAG_LEVEL_ENABLED LogFlags = 0b00000001
)
type OmniLog struct {
flags LogFlags
logs []ILog
}
func NewOmniLog(logs ...ILog) *OmniLog {
return &OmniLog{logs: logs}
}
func (log *OmniLog) Level(level LogLevel) {
if (log.flags & OMNI_FLAG_LEVEL_ENABLED) > 0 {
for _, ilog := range log.logs {
ilog.Level(level)
}
} else {
fmt.Println("WARNING: must use OMNI_FLAG_LEVEL_ENABLED to enabled OmniFlag.Level()!")
}
}
func (log *OmniLog) Flags(flags LogFlags) {
log.flags = flags
}
func (log *OmniLog) Debug(message string) {
for _, ilog := range log.logs {
ilog.Debug(message)
}
}
func (log *OmniLog) Info(message string) {
for _, ilog := range log.logs {
ilog.Info(message)
}
}
func (log *OmniLog) Warning(message string) {
for _, ilog := range log.logs {
ilog.Warning(message)
}
}
func (log *OmniLog) Error(message string) {
for _, ilog := range log.logs {
ilog.Error(message)
}
}
func (log *OmniLog) Critical(message string) {
for _, ilog := range log.logs {
ilog.Critical(message)
}
}
func (log *OmniLog) Close() error {
errs := make([]string, 0)
for _, ilog := range log.logs {
err := ilog.Close()
if err != nil {
errs = append(errs, err.Error())
}
}
if len(errs) > 0 {
return fmt.Errorf(
"1 or more errors occured during logs close: \n%s\n",
strings.Join(errs, "\n"),
)
}
return nil
}