From c9bac6be76ca6296ae3514c09d89d5ed6bb1ba31 Mon Sep 17 00:00:00 2001 From: Victor Agababov Date: Fri, 4 Dec 2020 09:55:09 -0800 Subject: [PATCH] Log if the deserialized line is semi-normal. (#1939) Right now they panic and we lose all the context. --- test/logstream/v2/stream.go | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/test/logstream/v2/stream.go b/test/logstream/v2/stream.go index c4a7472c7..815519fed 100644 --- a/test/logstream/v2/stream.go +++ b/test/logstream/v2/stream.go @@ -205,20 +205,27 @@ func (s *namespaceSource) handleLine(l []byte, pod string) { if site == "" { site = line.Caller } - // E 15:04:05.000 webhook-699b7b668d-9smk2 [route-controller] [default/testroute-xyz] this is my message - msg := fmt.Sprintf("%s %s %s [%s] [%s] %s", - strings.ToUpper(string(line.Level[0])), - line.Timestamp.Format(timeFormat), - pod, - site, - line.Key, - line.Message) + func() { + defer func() { + if err := recover(); err != nil { + logf("Invalid log format for pod %s: %s", pod, string(l)) + } + }() + // E 15:04:05.000 webhook-699b7b668d-9smk2 [route-controller] [default/testroute-xyz] this is my message + msg := fmt.Sprintf("%s %s %s [%s] [%s] %s", + strings.ToUpper(string(line.Level[0])), + line.Timestamp.Format(timeFormat), + pod, + site, + line.Key, + line.Message) - if line.Error != "" { - msg += " err=" + line.Error - } + if line.Error != "" { + msg += " err=" + line.Error + } - logf(msg) + logf(msg) + }() } }