-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
65 lines (47 loc) · 1.04 KB
/
logger.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
package sdk
import (
"context"
"os"
"time"
"github.com/rs/zerolog"
)
type Logger struct {
logger zerolog.Logger
}
func NewLogger() *Logger {
logger := zerolog.New(
zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339},
).Level(zerolog.TraceLevel).With().Timestamp().Caller().Logger()
return &Logger{logger: logger}
}
func (l *Logger) WithContext(ctx context.Context) *Logger {
l.logger.WithContext(ctx)
return l
}
func (l *Logger) AddStrField(k, v string) *Logger {
l.logger.Log().Str(k, v)
return l
}
func (l *Logger) AddIntField(k string, v int) *Logger {
l.logger.Log().Int(k, v)
return l
}
func (l *Logger) AddBoolField(k string, v bool) *Logger {
l.logger.Log().Bool(k, v)
return l
}
func (l *Logger) Debug(log string) {
l.logger.Debug().Msg(log)
}
func (l *Logger) Warn(log string) {
l.logger.Warn().Msg(log)
}
func (l *Logger) Info(log string) {
l.logger.Info().Msg(log)
}
func (l *Logger) Error(log string) {
l.logger.Error().Msg(log)
}
func (l *Logger) Fatal(log string) {
l.logger.Fatal().Msg(log)
}