-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.go
42 lines (36 loc) · 1.03 KB
/
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
package zcc
import (
"net/http"
"net/http/httputil"
)
const (
logReqMsg = `Request "%s %s" details:
---[ ZSCALER SDK REQUEST ]-------------------------------
%s
---------------------------------------------------------`
logRespMsg = `Response "%s %s" details:
---[ ZSCALER SDK RESPONSE ]--------------------------------
%s
-------------------------------------------------------`
)
func (client *Client) WriteLog(format string, args ...interface{}) {
if client.Config.Logger != nil {
client.Config.Logger.Printf(format, args...)
}
}
func (client *Client) logRequest(req *http.Request) {
if client.Config.Logger != nil && req != nil {
out, err := httputil.DumpRequestOut(req, true)
if err == nil {
client.WriteLog(logReqMsg, req.Method, req.URL, string(out))
}
}
}
func (client *Client) logResponse(resp *http.Response) {
if client.Config.Logger != nil && resp != nil {
out, err := httputil.DumpResponse(resp, true)
if err == nil {
client.WriteLog(logRespMsg, resp.Request.Method, resp.Request.URL, string(out))
}
}
}