-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.go
202 lines (185 loc) · 5.13 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/**
* @Time : 2019-07-02 17:18
* @Author : ygqbasic@gmail.com
* @File : logging
* @Software: VS Code
*/
package project
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/fuhsicloud/fuhsicloud/src/util/pods"
"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) Post(ctx context.Context, ns, name, displayName, desc string) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Post",
"namespace", ns,
"name", name,
"displayName", displayName,
"desc", desc,
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.Post(ctx, ns, name, displayName, desc)
}
func (s *loggingService) BasicPost(ctx context.Context, name string, req basicRequest) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "BasicPost",
"namespace", req.Namespace,
"name", req.Name,
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.BasicPost(ctx, name, req)
}
func (s *loggingService) List(ctx context.Context, page, limit int, name string, groupId int64) (res map[string]interface{}, err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "List",
"name", name,
"page", page,
"limit", limit,
"groupId", groupId,
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.List(ctx, page, limit, name, groupId)
}
func (s *loggingService) ListByNs(ctx context.Context) (res []map[string]interface{}, err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "ListByNs",
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.ListByNs(ctx)
}
func (s *loggingService) PomFile(ctx context.Context, pomFile string) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "PomFile",
"took", time.Since(begin),
"pomFile", pomFile,
"err", err,
)
}(time.Now())
return s.Service.PomFile(ctx, pomFile)
}
func (s *loggingService) GitAddr(ctx context.Context, gitAddr string) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "GitAddr",
"took", time.Since(begin),
"gitAddr", gitAddr,
"err", err,
)
}(time.Now())
return s.Service.GitAddr(ctx, gitAddr)
}
func (s *loggingService) Detail(ctx context.Context) (res map[string]interface{}, err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Detail",
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.Detail(ctx)
}
func (s *loggingService) Update(ctx context.Context, displayName, desc string) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Update",
"took", time.Since(begin),
"displayName", displayName,
"desc", desc,
"err", err,
)
}(time.Now())
return s.Service.Update(ctx, displayName, desc)
}
func (s *loggingService) Sync(ctx context.Context) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Sync",
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.Sync(ctx)
}
func (s *loggingService) Delete(ctx context.Context, ns, name, code string) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Delete",
"name", name,
"namespace", ns,
"code", code,
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.Delete(ctx, ns, name, code)
}
func (s *loggingService) Config(ctx context.Context) (res map[string]interface{}, err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Config",
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.Config(ctx)
}
func (s *loggingService) Monitor(ctx context.Context, metrics, podName, container string) (res map[string]map[string]map[string][]pods.XYRes, err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Monitor",
"metrics", metrics,
"podName", podName,
"container", container,
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.Monitor(ctx, metrics, podName, container)
}
func (s *loggingService) Alerts(ctx context.Context) (res alertsResponse, err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Alerts",
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.Alerts(ctx)
}