github.com/glycerine/docker@v1.8.2/pkg/jsonlog/jsonlog.go (about) 1 package jsonlog 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "time" 7 ) 8 9 type JSONLog struct { 10 Log string `json:"log,omitempty"` 11 Stream string `json:"stream,omitempty"` 12 Created time.Time `json:"time"` 13 } 14 15 func (jl *JSONLog) Format(format string) (string, error) { 16 if format == "" { 17 return jl.Log, nil 18 } 19 if format == "json" { 20 m, err := json.Marshal(jl) 21 return string(m), err 22 } 23 return fmt.Sprintf("%s %s", jl.Created.Format(format), jl.Log), nil 24 } 25 26 func (jl *JSONLog) Reset() { 27 jl.Log = "" 28 jl.Stream = "" 29 jl.Created = time.Time{} 30 }