Skip to content
Snippets Groups Projects
Commit d9423fd8e23b authored by Christophe de Vienne's avatar Christophe de Vienne
Browse files

SQLTrace: limit argument size to 512 bytes

parent 88cf4ccfe86f
No related branches found
No related tags found
No related merge requests found
Pipeline #31077 failed
......@@ -3,6 +3,7 @@
import (
"context"
"database/sql"
"encoding/json"
"strings"
"github.com/Masterminds/squirrel"
......@@ -27,7 +28,18 @@
if log != nil && log.GetLevel() < 0 {
arr := zerolog.Arr()
for _, arg := range args {
arr.Interface(arg)
b, err := json.Marshal(arg)
if err != nil {
arr.Interface(arg)
} else {
if len(b) > 512 {
b, _ = json.Marshal(map[string]interface{}{
"arg first 512 bytes": b[:512],
"len": len(b),
})
}
arr.RawJSON(b)
}
}
logger := log.With().Array("args", arr).Logger()
logger.Trace().Msg("SQL: " + sql)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment