Commit f8710dfb authored by Cloud User's avatar Cloud User

fix log output

parent 04d93dd6
......@@ -3,6 +3,7 @@ package main
import (
"bytes"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io"
......@@ -981,7 +982,17 @@ func main() {
// baseAttributes := []slog.Attr{}
// baseAttributes = append(baseAttributes, slog.String(TaskIdAtrr, taskId))
newAttributes := append(baseAttributes, slog.Int("resAsPb.TaskResultCode", int(res.TaskResultCode)), slog.String("TaskResultHeader", string(res.TaskResultHeader)), slog.String("TaskResultBody", string(res.TaskResultBody)))
newAttributes := append(baseAttributes, slog.Int("resAsPb.TaskResultCode", int(res.TaskResultCode)))
// slog.String("TaskResultHeader", string(res.TaskResultHeader)), slog.String("TaskResultBody", string(res.TaskResultBody)))
newAttributes = append(newAttributes, slog.String("TaskResultHeader", string(res.TaskResultHeader)))
if isBase64(res.TaskResultBody) {
newAttributes = append(newAttributes, slog.Int("TaskResultBody as Base64", len(res.TaskResultBody)))
} else {
newAttributes = append(newAttributes, slog.String("TaskResultBody", string(res.TaskResultBody)))
}
//if len(res.TaskResultBody) >
slog.LogAttrs(c.UserContext(), slog.LevelInfo, "getAsyncRes", newAttributes...)
......@@ -1228,23 +1239,23 @@ func ApiOrJWT(c *fiber.Ctx) error {
Bytes: pbBytes,
}
asyncMode := true
asyncMode := false
// for k, v := range reqHeaders {
// fmt.Println("k-------", k, "v", v)
// }
if headerSync, ok := reqHeaders["Async"]; ok {
if headerSync, ok := reqHeaders["Prefer"]; ok {
for _, syncAsString := range headerSync {
if syncAsString == "true" {
if syncAsString == "respond-async" {
asyncMode = true
break
}
} else {
if syncAsString == "false" {
asyncMode = false
break
}
}
}
......@@ -1267,6 +1278,11 @@ func ApiOrJWT(c *fiber.Ctx) error {
}
}
func isBase64(s []byte) bool {
_, err := base64.StdEncoding.DecodeString(string(s))
return err == nil
}
func syncModeF(c *fiber.Ctx, taskid string) error {
wait := syncReq(taskid)
......@@ -1274,7 +1290,16 @@ func syncModeF(c *fiber.Ctx, taskid string) error {
baseAttributes := []slog.Attr{}
baseAttributes = append(baseAttributes, slog.String(TaskIdAtrr, taskid))
newAttributes := append(baseAttributes, slog.Int("resAsPb.TaskResultCode", int(resAsPb.TaskResultCode)), slog.String("TaskResultHeader", string(resAsPb.TaskResultHeader)), slog.String("TaskResultBody", string(resAsPb.TaskResultBody)))
// newAttributes := append(baseAttributes, slog.Int("resAsPb.TaskResultCode", int(resAsPb.TaskResultCode)), slog.String("TaskResultHeader", string(resAsPb.TaskResultHeader)), slog.String("TaskResultBody", string(resAsPb.TaskResultBody)))
newAttributes := append(baseAttributes, slog.Int("resAsPb.TaskResultCode", int(resAsPb.TaskResultCode)))
newAttributes = append(newAttributes, slog.String("TaskResultHeader", string(resAsPb.TaskResultHeader)))
if isBase64(resAsPb.TaskResultBody) {
newAttributes = append(newAttributes, slog.Int("TaskResultBody as Base64", len(resAsPb.TaskResultBody)))
} else {
newAttributes = append(newAttributes, slog.String("TaskResultBody", string(resAsPb.TaskResultBody)))
}
slog.LogAttrs(c.UserContext(), slog.LevelInfo, "syncModeF", newAttributes...)
......@@ -1396,9 +1421,15 @@ func Return(c *fiber.Ctx, resAsPb pbUpstream.TaskResponse, baseAttributes []slog
slog.String("TaskError", resAsJson.Task.TaskError),
slog.String("ExecCode", resAsJson.Task.ExecCode),
slog.String("ExecError", resAsJson.Task.ExecError),
slog.String("Output", string(resAsJson.Output)),
//slog.String("Output", string(resAsJson.Output)),
)
if isBase64(resAsPb.TaskResultBody) {
newAttributes = append(newAttributes, slog.Int("TaskResultBody as Base64", len(resAsPb.TaskResultBody)))
} else {
newAttributes = append(newAttributes, slog.String("TaskResultBody", string(resAsPb.TaskResultBody)))
}
slog.LogAttrs(c.UserContext(), slog.LevelInfo, "http return", newAttributes...)
return c.JSON(resAsJson)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment