This repository has been archived by the owner on Mar 16, 2022. It is now read-only.
/
logging.go
113 lines (103 loc) · 2.8 KB
/
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
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
113
/**
* @Time : 2019-07-12 11:55
* @Author : solacowa@gmail.com
* @File : logging
* @Software: GoLand
*/
package permission
import (
"context"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
kithttp "github.com/go-kit/kit/transport/http"
"github.com/kplcloud/kplcloud/src/repository/types"
"time"
)
type loggingService struct {
logger log.Logger
Service
}
func NewLoggingService(logger log.Logger, s Service) Service {
return &loggingService{level.Info(logger), s}
}
func (s *loggingService) Delete(ctx context.Context, id int64) (res []*types.Permission, err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "sync",
"took", time.Since(begin),
"id", id,
"err", err,
)
}(time.Now())
return s.Service.Delete(ctx, id)
}
func (s *loggingService) Update(ctx context.Context, id int64, icon, keyType string, menu bool, name, path, method string) (res []*types.Permission, err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Update",
"took", time.Since(begin),
"id", id,
"icon", icon,
"keyType", keyType,
"menu", menu,
"name", name,
"path", path,
"m", method,
"err", err,
)
}(time.Now())
return s.Service.Update(ctx, id, icon, keyType, menu, name, path, method)
}
func (s *loggingService) Post(ctx context.Context, name, path, method, icon string, isMenu bool, parentId int64) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Post",
"took", time.Since(begin),
"icon", icon,
"menu", isMenu,
"name", name,
"path", path,
"m", method,
"err", err,
)
}(time.Now())
return s.Service.Post(ctx, name, path, method, icon, isMenu, parentId)
}
func (s *loggingService) Drag(ctx context.Context, dragKey, dropKey int64) (res []*types.Permission, err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Drag",
"took", time.Since(begin),
"dragKey", dragKey,
"dropKey", dropKey,
"err", err,
)
}(time.Now())
return s.Service.Drag(ctx, dragKey, dropKey)
}
func (s *loggingService) Menu(ctx context.Context) (res []*types.Permission, err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Menu",
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.Menu(ctx)
}
func (s *loggingService) List(ctx context.Context) (res []*types.Permission, err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "List",
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.List(ctx)
}