-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomain.go
112 lines (93 loc) · 2.51 KB
/
domain.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
108
109
110
111
112
package log
import (
"time"
"github.com/fatih/color"
)
// colors.
const (
none = 0
red = 31
green = 32
yellow = 33
blue = 34
gray = 37
)
// Log levels.
const (
InvalidLevel Level = iota - 1
LevelDebug
LevelInfo
LevelWarn
LevelError
LevelFatal
)
// Colors mapping.
var Colors = [...]color.Attribute{
LevelDebug: color.FgWhite,
LevelInfo: color.FgBlue,
LevelWarn: color.FgYellow,
LevelError: color.FgRed,
LevelFatal: color.FgRed,
}
var LevelNames = [...]string{
LevelDebug: "debug",
LevelInfo: "info",
LevelWarn: "warn",
LevelError: "error",
LevelFatal: "fatal",
}
var LevelStrings = map[string]Level{
"debug": LevelDebug,
"info": LevelInfo,
"warn": LevelWarn,
"error": LevelError,
"fatal": LevelFatal,
}
func LevelFromString(s string) Level {
return LevelStrings[s]
}
type Tags map[string]string
type Fields map[string]interface{}
type Level int
type Logger interface {
Debug(msg interface{}, more ...interface{}) Telemetry
Info(msg interface{}, more ...interface{}) Telemetry
Warn(msg interface{}, more ...interface{}) Telemetry
Error(msg interface{}, more ...interface{}) Telemetry
Fatal(msg interface{}, more ...interface{}) Telemetry
Debugf(msg string, v ...interface{}) Telemetry
Infof(msg string, v ...interface{}) Telemetry
Warnf(msg string, v ...interface{}) Telemetry
Errorf(msg string, v ...interface{}) Telemetry
Fatalf(msg string, v ...interface{}) Telemetry
WithField(s string, v interface{}) Logger
WithFields(Fields) Logger
WithError(...error) Logger
WithErrors(...error) Logger
WithTags(t Tags) Telemetry
WithTag(string, string) Telemetry
Clone() Logger
}
type Payload struct {
Level Level `json:"level,omitempty"`
Messages []interface{} `json:"messages,omitempty"`
Fields Fields `json:"fields,omitempty"`
Timestamp time.Time `json:"ts,omitempty"`
Tags Tags `json:"tags,omitempty"`
Errors []string `json:"Errors,omitempty"`
ElapsedSinceStart time.Duration `json:"ElapsedSinceStart,omitempty"`
}
type Writer interface {
WriteLog(payload *Payload)
}
type Telemetry interface {
WithTags(t Tags) Telemetry
WithTag(string, string) Telemetry
Inc(name string, value float64, extra ...interface{}) Logger
Gauge(string, float64, ...interface{}) Logger
Fix(string, float64, ...interface{}) Logger
Histogram(name string, value float64, extra ...interface{}) Logger
Summary(name string, value float64, extra ...interface{}) Logger
Clone() Telemetry
SetLogger(l Logger)
}