mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
d3b3ebc3a4
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
30 lines
545 B
Go
30 lines
545 B
Go
package jsonlog
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type JSONLog struct {
|
|
Log string `json:"log,omitempty"`
|
|
Stream string `json:"stream,omitempty"`
|
|
Created time.Time `json:"time"`
|
|
}
|
|
|
|
func (jl *JSONLog) Format(format string) (string, error) {
|
|
if format == "" {
|
|
return jl.Log, nil
|
|
}
|
|
if format == "json" {
|
|
m, err := json.Marshal(jl)
|
|
return string(m), err
|
|
}
|
|
return fmt.Sprintf("%s %s", jl.Created.Format(format), jl.Log), nil
|
|
}
|
|
|
|
func (jl *JSONLog) Reset() {
|
|
jl.Log = ""
|
|
jl.Stream = ""
|
|
jl.Created = time.Time{}
|
|
}
|