pkg/jsonlog: avoid JSONLog allocation in loop
Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
This commit is contained in:
parent
be805c6709
commit
deaded4ca8
1 changed files with 8 additions and 2 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue