diff --git a/managedplugin/logging.go b/managedplugin/logging.go index 131a31d..fee7de0 100644 --- a/managedplugin/logging.go +++ b/managedplugin/logging.go @@ -4,9 +4,8 @@ import "github.com/rs/zerolog" func (c *Client) jsonToLog(l zerolog.Logger, msg map[string]any) { level := msg["level"] - // Delete fields already added by the CLI so that they don't appear twice in the logs when we stream it from plugins + // The log level is part of the log message received from the plugin, so we need to remove it before logging delete(msg, "level") - delete(msg, "invocation_id") switch level { case "trace": l.Trace().Fields(msg).Msg("") diff --git a/managedplugin/plugin.go b/managedplugin/plugin.go index a9d7338..981c032 100644 --- a/managedplugin/plugin.go +++ b/managedplugin/plugin.go @@ -548,6 +548,8 @@ func (c *Client) getPluginArgs() []string { func (c *Client) readLogLines(reader io.ReadCloser) { defer c.wg.Done() lr := NewLogReader(reader) + // reset the context to avoid duplicate fields in the logs when streaming logs from plugins + pluginsLogger := c.logger.With().Reset().Timestamp().Logger() for { line, err := lr.NextLine() if errors.Is(err, io.EOF) { @@ -565,7 +567,7 @@ func (c *Client) readLogLines(reader io.ReadCloser) { if err := json.Unmarshal(line, &structuredLogLine); err != nil { c.logger.Info().Str("level", "unknown").Msg(string(line)) } else { - c.jsonToLog(c.logger, structuredLogLine) + c.jsonToLog(pluginsLogger, structuredLogLine) } } }