Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ai-api-mgr
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
ai-api-mgr
Commits
f8710dfb
Commit
f8710dfb
authored
Mar 20, 2024
by
Cloud User
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix log output
parent
04d93dd6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
8 deletions
+39
-8
main.go
main.go
+39
-8
No files found.
main.go
View file @
f8710dfb
...
...
@@ -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
:=
tru
e
asyncMode
:=
fals
e
// 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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment