pkg/jsonlog: avoid JSONLog allocation in loop

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
Upstream-commit: 473bb5274ce7a520bc73ccb3529f99729a799062
Component: engine
This commit is contained in:
unclejack
2014-09-18 18:04:18 +03:00
parent 3b7b455265
commit 98789bf31d

View File

@ -25,11 +25,16 @@ func (jl *JSONLog) Format(format string) (string, error) {
return fmt.Sprintf("[%s] %s", jl.Created.Format(format), jl.Log), nil
}
func (jl *JSONLog) Reset() {
jl.Log = ""
jl.Stream = ""
jl.Created = time.Time{}
}
func WriteLog(src io.Reader, dst io.Writer, format string) error {
dec := json.NewDecoder(src)
l := &JSONLog{}
for {
l := &JSONLog{}
if err := dec.Decode(l); err == io.EOF {
return nil
} else if err != nil {
@ -43,5 +48,6 @@ func WriteLog(src io.Reader, dst io.Writer, format string) error {
if _, err := io.WriteString(dst, line); err != nil {
return err
}
l.Reset()
}
}