forked from pydio/cells
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calls-logger.go
90 lines (72 loc) · 2.98 KB
/
calls-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
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
/*
* Copyright (c) 2018-2021. Abstrium SAS <team (at) pydio.com>
* This file is part of Pydio Cells.
*
* Pydio Cells is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio Cells is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio Cells. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <https://pydio.com>.
*/
package wrappers
import (
"context"
"fmt"
"github.com/micro/go-micro/client"
)
func WithCallsLogger(c client.Client) client.Client {
return &callsLogger{w: c}
}
type callsLogger struct {
w client.Client
}
func (c *callsLogger) logRequest(callType string, req client.Request) {
fmt.Printf("%s\t%s\t%s\n", callType, req.Service(), req.Method())
}
func (c *callsLogger) Init(option ...client.Option) error {
return c.w.Init(option...)
}
func (c *callsLogger) Options() client.Options {
return c.w.Options()
}
func (c *callsLogger) NewPublication(topic string, msg interface{}) client.Publication {
return c.w.NewPublication(topic, msg)
}
func (c *callsLogger) NewRequest(service, method string, req interface{}, reqOpts ...client.RequestOption) client.Request {
return c.w.NewRequest(service, method, req, reqOpts...)
}
func (c *callsLogger) NewProtoRequest(service, method string, req interface{}, reqOpts ...client.RequestOption) client.Request {
return c.w.NewProtoRequest(service, method, req, reqOpts...)
}
func (c *callsLogger) NewJsonRequest(service, method string, req interface{}, reqOpts ...client.RequestOption) client.Request {
return c.w.NewJsonRequest(service, method, req, reqOpts...)
}
func (c *callsLogger) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error {
c.logRequest("Call", req)
return c.w.Call(ctx, req, rsp, opts...)
}
func (c *callsLogger) CallRemote(ctx context.Context, addr string, req client.Request, rsp interface{}, opts ...client.CallOption) error {
return c.w.CallRemote(ctx, addr, req, rsp, opts...)
}
func (c *callsLogger) Stream(ctx context.Context, req client.Request, opts ...client.CallOption) (client.Streamer, error) {
c.logRequest("Stream", req)
return c.w.Stream(ctx, req, opts...)
}
func (c *callsLogger) StreamRemote(ctx context.Context, addr string, req client.Request, opts ...client.CallOption) (client.Streamer, error) {
return c.w.StreamRemote(ctx, addr, req, opts...)
}
func (c *callsLogger) Publish(ctx context.Context, p client.Publication, opts ...client.PublishOption) error {
return c.w.Publish(ctx, p, opts...)
}
func (c *callsLogger) String() string {
return c.w.String()
}