diff --git a/api/types/backend/backend.go b/api/types/backend/backend.go index 9880c632bd..29d92026c4 100644 --- a/api/types/backend/backend.go +++ b/api/types/backend/backend.go @@ -38,8 +38,6 @@ type PartialLogMetaData struct { // LogMessage is datastructure that represents piece of output produced by some // container. The Line member is a slice of an array whose contents can be // changed after a log driver's Log() method returns. -// changes to this struct need to be reflect in the reset method in -// daemon/logger/logger.go type LogMessage struct { Line []byte Source string diff --git a/daemon/logger/logger.go b/daemon/logger/logger.go index 6308270b20..15899e07ed 100644 --- a/daemon/logger/logger.go +++ b/daemon/logger/logger.go @@ -49,20 +49,12 @@ func PutMessage(msg *Message) { // Message is subtyped from backend.LogMessage because there is a lot of // internal complexity around the Message type that should not be exposed // to any package not explicitly importing the logger type. -// -// Any changes made to this struct must also be updated in the `reset` function type Message backend.LogMessage // reset sets the message back to default values // This is used when putting a message back into the message pool. -// Any changes to the `Message` struct should be reflected here. func (m *Message) reset() { - m.Line = m.Line[:0] - m.Source = "" - m.Attrs = nil - m.PLogMetaData = nil - - m.Err = nil + *m = Message{Line: m.Line[:0]} } // AsLogMessage returns a pointer to the message as a pointer to diff --git a/daemon/logger/loggerutils/logfile.go b/daemon/logger/loggerutils/logfile.go index d4f3f5e149..9319ce5818 100644 --- a/daemon/logger/loggerutils/logfile.go +++ b/daemon/logger/loggerutils/logfile.go @@ -156,7 +156,9 @@ func (w *LogFile) WriteLogEntry(msg *logger.Message) error { return errors.Wrap(err, "error marshalling log message") } + ts := msg.Timestamp logger.PutMessage(msg) + msg = nil // Turn use-after-put bugs into panics. w.mu.Lock() if w.closed { @@ -172,7 +174,7 @@ func (w *LogFile) WriteLogEntry(msg *logger.Message) error { n, err := w.f.Write(b) if err == nil { w.currentSize += int64(n) - w.lastTimestamp = msg.Timestamp + w.lastTimestamp = ts } w.mu.Unlock()