forked from porthos-rpc/porthos-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccesslog.go
35 lines (28 loc) · 1005 Bytes
/
accesslog.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
package porthos
import (
"time"
"github.com/porthos-rpc/porthos-go/log"
)
// AccessLogExtension logs incoming requests and outgoing responses.
type AccessLogExtension struct {
}
// ServerListening this is not implemented in this extension.
func (a *AccessLogExtension) ServerListening(server Server) {}
// IncomingRequest logs rpc request method and arguments.
func (a *AccessLogExtension) IncomingRequest(req Request) {
log.Info("Method [%s] Arguments [%s]",
req.GetMethodName(),
string(req.GetBody()))
}
// OutgoingResponse logs rpc response details.
func (a *AccessLogExtension) OutgoingResponse(req Request, res Response, resTime time.Duration, statusCode int32) {
log.Info("Method [%s] Arguments [%s] Status Code [%d] Response Time [%fms]",
req.GetMethodName(),
string(req.GetBody()),
statusCode,
resTime.Seconds()*1000)
}
// NewAccessLogExtension creates a new extension that logs everything to stdout.
func NewAccessLogExtension() Extension {
return &AccessLogExtension{}
}