This repository has been archived by the owner on Mar 16, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 206
/
logging.go
119 lines (108 loc) · 3.05 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
/**
* @Time : 2019-07-17 14:18
* @Author : solacowa@gmail.com
* @File : logging
* @Software: GoLand
*/
package member
import (
"context"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
kithttp "github.com/go-kit/kit/transport/http"
"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) Namespaces(ctx context.Context) (list []map[string]string, err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Namespaces",
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.Namespaces(ctx)
}
func (s *loggingService) Detail(ctx context.Context, id int64) (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, id)
}
func (s *loggingService) Post(ctx context.Context, username, email, password string, state int64, namespaces []string, roleIds []int64) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Post",
"username", username,
"email", email,
"state", state,
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.Post(ctx, username, email, password, state, namespaces, roleIds)
}
func (s *loggingService) Update(ctx context.Context, id int64, username, email, password string, state int64, namespaces []string, roleIds []int64) (err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Update",
"id", id,
"username", username,
"email", email,
"state", state,
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.Update(ctx, id, username, email, password, state, namespaces, roleIds)
}
func (s *loggingService) List(ctx context.Context, page, limit int, email string) (rs map[string]interface{}, err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Update",
"page", page,
"limit", limit,
"email", email,
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.List(ctx, page, limit, email)
}
func (s *loggingService) Me(ctx context.Context) (res map[string]interface{}, err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "Me",
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.Me(ctx)
}
func (s *loggingService) All(ctx context.Context) (res interface{}, err error) {
defer func(begin time.Time) {
_ = s.logger.Log(
"uri", ctx.Value(kithttp.ContextKeyRequestURI),
"method", "All",
"took", time.Since(begin),
"err", err,
)
}(time.Now())
return s.Service.All(ctx)
}