forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware_logging.go
84 lines (74 loc) · 2.47 KB
/
middleware_logging.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
package notebooks
import (
"context"
"time"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kit/platform"
"go.uber.org/zap"
)
func NewLoggingService(logger *zap.Logger, underlying influxdb.NotebookService) *loggingService {
return &loggingService{
logger: logger,
underlying: underlying,
}
}
type loggingService struct {
logger *zap.Logger
underlying influxdb.NotebookService
}
var _ influxdb.NotebookService = (*loggingService)(nil)
func (l loggingService) GetNotebook(ctx context.Context, id platform.ID) (n *influxdb.Notebook, err error) {
defer func(start time.Time) {
dur := zap.Duration("took", time.Since(start))
if err != nil {
l.logger.Debug("failed to find notebook by ID", zap.Error(err), dur)
return
}
l.logger.Debug("notebook find by ID", dur)
}(time.Now())
return l.underlying.GetNotebook(ctx, id)
}
func (l loggingService) CreateNotebook(ctx context.Context, create *influxdb.NotebookReqBody) (n *influxdb.Notebook, err error) {
defer func(start time.Time) {
dur := zap.Duration("took", time.Since(start))
if err != nil {
l.logger.Debug("failed to create notebook", zap.Error(err), dur)
return
}
l.logger.Debug("notebook create", dur)
}(time.Now())
return l.underlying.CreateNotebook(ctx, create)
}
func (l loggingService) UpdateNotebook(ctx context.Context, id platform.ID, update *influxdb.NotebookReqBody) (n *influxdb.Notebook, err error) {
defer func(start time.Time) {
dur := zap.Duration("took", time.Since(start))
if err != nil {
l.logger.Debug("failed to update notebook", zap.Error(err), dur)
return
}
l.logger.Debug("notebook update", dur)
}(time.Now())
return l.underlying.UpdateNotebook(ctx, id, update)
}
func (l loggingService) DeleteNotebook(ctx context.Context, id platform.ID) (err error) {
defer func(start time.Time) {
dur := zap.Duration("took", time.Since(start))
if err != nil {
l.logger.Debug("failed to delete notebook", zap.Error(err), dur)
return
}
l.logger.Debug("notebook delete", dur)
}(time.Now())
return l.underlying.DeleteNotebook(ctx, id)
}
func (l loggingService) ListNotebooks(ctx context.Context, filter influxdb.NotebookListFilter) (ns []*influxdb.Notebook, err error) {
defer func(start time.Time) {
dur := zap.Duration("took", time.Since(start))
if err != nil {
l.logger.Debug("failed to find notebooks", zap.Error(err), dur)
return
}
l.logger.Debug("notebooks find", dur)
}(time.Now())
return l.underlying.ListNotebooks(ctx, filter)
}