-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogs.go
More file actions
57 lines (44 loc) · 1.05 KB
/
logs.go
File metadata and controls
57 lines (44 loc) · 1.05 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
package errors
import (
"strings"
"github.com/yanun0323/errors/internal/logs"
)
// make errorStack implements tsf interface
var (
_ logs.Error = (*errorStack)(nil)
_ logs.Frame = (*frame)(nil)
_ logs.Attr = (*attr)(nil)
)
func (e *errorStack) Message() string {
return e.message
}
func (e *errorStack) Cause() error {
return e.cause
}
func (e *errorStack) Stack() []any {
frames := make([]any, 0, len(e.stack))
for _, frame := range e.stack {
frames = append(frames, frame)
}
return frames
}
func (e *errorStack) Attributes() []any {
attrs := make([]any, 0, len(e.attr))
for _, attr := range e.attr {
attrs = append(attrs, attr)
}
return attrs
}
func (f frame) Parameters() (file, function, line string) {
return f.File, f.Function, f.Line
}
func (a attr) Parameters() (key string, value any) {
buf := stringBuilderPool.Get().(*strings.Builder)
defer stringBuilderPool.Put(buf)
buf.Reset()
buf.Grow(len(a.Function) + len(a.Key) + 1)
buf.WriteString(a.Function)
buf.WriteByte('.')
buf.WriteString(a.Key)
return buf.String(), a.Value
}