Merge branch 'MSP-333_xml_log_support' into 'master'
Resolve MSP-333 "Xml log support" Closes MSP-333 See merge request integration-system/isp-gate-service!5
This commit is contained in:
commit
104524855c
3 files changed
+19
-4
No files matched your search
@@ -1,3 +1,5 @@
|
||||
### v2.8.1
|
||||
* add xml format support for new logger
|
||||
### v2.8.0
|
||||
* add new logger
|
||||
* remove journal
|
||||
|
||||
+16
-3
@@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -43,7 +44,6 @@ func (h Handler) CompleteRequest(ctx *fasthttp.RequestCtx) {
|
||||
currentTime := time.Now()
|
||||
|
||||
appId, adminId, path, resp := h.authenticateAccountingProxy(ctx)
|
||||
|
||||
executionTime := time.Since(currentTime) / execution
|
||||
|
||||
statusCode := ctx.Response.StatusCode()
|
||||
@@ -52,6 +52,8 @@ func (h Handler) CompleteRequest(ctx *fasthttp.RequestCtx) {
|
||||
service.Metrics.UpdateMethodResponseTime(path, executionTime)
|
||||
}
|
||||
|
||||
reqContentType := ctx.Request.Header.ContentType()
|
||||
resContentType := ctx.Response.Header.ContentType()
|
||||
logEnable := config.GetRemote().(*conf.RemoteConfig).JournalSetting.Journal.Enable
|
||||
// nolintlint
|
||||
if logEnable && matcher.JournalMethods.Match(path) {
|
||||
@@ -64,8 +66,8 @@ func (h Handler) CompleteRequest(ctx *fasthttp.RequestCtx) {
|
||||
zap.String("path", path),
|
||||
zap.Int32("application_id", appId),
|
||||
zap.Int64("admin_id", adminId),
|
||||
zap.Any("request", json.RawMessage(requestBody)),
|
||||
zap.Any("response", json.RawMessage(responseBody)),
|
||||
zap.Any("request", castData(requestBody, reqContentType)),
|
||||
zap.Any("response", castData(responseBody, resContentType)),
|
||||
zap.Error(err),
|
||||
}
|
||||
if err != nil {
|
||||
@@ -76,6 +78,17 @@ func (h Handler) CompleteRequest(ctx *fasthttp.RequestCtx) {
|
||||
}
|
||||
}
|
||||
|
||||
var jsonContentType = []byte("application/json")
|
||||
|
||||
func castData(data []byte, contentType []byte) interface{} {
|
||||
switch {
|
||||
case bytes.Contains(contentType, jsonContentType):
|
||||
return json.RawMessage(data)
|
||||
default:
|
||||
return fmt.Sprintf("%s", data)
|
||||
}
|
||||
}
|
||||
|
||||
func (h Handler) authenticateAccountingProxy(ctx *fasthttp.RequestCtx) (int32, int64, string, domain.ProxyResponse) {
|
||||
var (
|
||||
appId int32 = -1
|
||||
|
||||
Reference in new issue
Block a user