diff --git a/pkg/executor/executor.go b/pkg/executor/executor.go index 1cd197a0..a9723578 100644 --- a/pkg/executor/executor.go +++ b/pkg/executor/executor.go @@ -85,6 +85,7 @@ func (pj *proxyJSONLogger) Write(p []byte) (int, error) { return len(p), nil } + // join all parts of json pj.buf = append(pj.buf, p...) var line interface{} @@ -108,11 +109,21 @@ func (pj *proxyJSONLogger) Write(p []byte) (int, error) { logMap[k] = v } - logLine, _ := json.Marshal(logMap) + logLineRaw, _ := json.Marshal(logMap) + + logLine := string(logLineRaw) + + if len(logLine) > 10000 { + logLine = fmt.Sprintf("%s:truncated", string(logLine[:10000])) + } + + truncetedLog, _ := json.Marshal(map[string]string{ + "truncated": logLine, + }) logEntry := pj.WithField(app.ProxyJsonLogKey, true) - logEntry.Log(log.FatalLevel, string(logLine)) + logEntry.Log(log.FatalLevel, string(truncetedLog)) return len(p), nil } @@ -144,6 +155,10 @@ func (pj *proxyJSONLogger) writerScanner(p []byte) { continue } + if len(str) > 10000 { + str = fmt.Sprintf("%s:truncated", str[:10000]) + } + pj.Entry.Info(str) } diff --git a/pkg/executor/executor_test.go b/pkg/executor/executor_test.go index ad175c2d..a3cae4d3 100644 --- a/pkg/executor/executor_test.go +++ b/pkg/executor/executor_test.go @@ -55,7 +55,7 @@ func TestRunAndLogLines(t *testing.T) { cmd := exec.Command("cat", f.Name()) _, err = RunAndLogLines(cmd, map[string]string{"a": "b"}) assert.NoError(t, err) - assert.Contains(t, buf.String(), `\",\"output\":\"stdout\"}" a=b output=stdout proxyJsonLog=true`) + assert.Contains(t, buf.String(), `:truncated\"}" a=b output=stdout proxyJsonLog=true`) buf.Reset() })