-
Notifications
You must be signed in to change notification settings - Fork 69
/
log.go
107 lines (98 loc) · 3.19 KB
/
log.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 log
import (
"context"
"time"
"github.com/goravel/framework/contracts/http"
)
const (
StackDriver = "stack"
SingleDriver = "single"
DailyDriver = "daily"
CustomDriver = "custom"
)
const (
PanicLevel Level = iota
FatalLevel
ErrorLevel
WarningLevel
InfoLevel
DebugLevel
)
type Log interface {
// WithContext adds a context to the logger.
WithContext(ctx context.Context) Writer
// Channel return a writer for a specific channel.
Channel(channel string) Writer
// Stack return a writer for multiple channels.
Stack(channels []string) Writer
Writer
}
type Writer interface {
// Debug logs a message at DebugLevel.
Debug(args ...any)
// Debugf is equivalent to Debug, but with support for fmt.Printf-style arguments.
Debugf(format string, args ...any)
// Info logs a message at InfoLevel.
Info(args ...any)
// Infof is equivalent to Info, but with support for fmt.Printf-style arguments.
Infof(format string, args ...any)
// Warning logs a message at WarningLevel.
Warning(args ...any)
// Warningf is equivalent to Warning, but with support for fmt.Printf-style arguments.
Warningf(format string, args ...any)
// Error logs a message at ErrorLevel.
Error(args ...any)
// Errorf is equivalent to Error, but with support for fmt.Printf-style arguments.
Errorf(format string, args ...any)
// Fatal logs a message at FatalLevel.
Fatal(args ...any)
// Fatalf is equivalent to Fatal, but with support for fmt.Printf-style arguments.
Fatalf(format string, args ...any)
// Panic logs a message at PanicLevel.
Panic(args ...any)
// Panicf is equivalent to Panic, but with support for fmt.Printf-style arguments.
Panicf(format string, args ...any)
// Code set a code or slug that describes the error.
// Error messages are intended to be read by humans, but such code is expected to
// be read by machines and even transported over different services.
Code(code string) Writer
// Hint set a hint for faster debugging.
Hint(hint string) Writer
// In sets the feature category or domain in which the log entry is relevant.
In(domain string) Writer
// Owner set the name/email of the colleague/team responsible for handling this error.
// Useful for alerting purpose.
Owner(owner any) Writer
// Request supplies a http.Request.
Request(req http.ContextRequest) Writer
// Response supplies a http.Response.
Response(res http.ContextResponse) Writer
// Tags add multiple tags, describing the feature returning an error.
Tags(tags ...string) Writer
// User sets the user associated with the log entry.
User(user any) Writer
// With adds key-value pairs to the context of the log entry
With(data map[string]any) Writer
// WithTrace adds a stack trace to the log entry.
WithTrace() Writer
}
type Logger interface {
// Handle pass a channel config path here
Handle(channel string) (Hook, error)
}
type Hook interface {
// Levels monitoring level
Levels() []Level
// Fire executes logic when trigger
Fire(Entry) error
}
type Entry interface {
// Context returns the context of the entry.
Context() context.Context
// Level returns the level of the entry.
Level() Level
// Time returns the timestamp of the entry.
Time() time.Time
// Message returns the message of the entry.
Message() string
}