utils.Debugf -> log.Printf, move jsonlog to own package.
Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh) Upstream-commit: 5cdb9c8acab75df74d20cd937e4091dacb355160 Component: engine
This commit is contained in:
@ -6,7 +6,6 @@ import (
|
||||
"crypto/sha1"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@ -19,7 +18,6 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/dockerversion"
|
||||
)
|
||||
@ -264,42 +262,6 @@ func (r *bufReader) Close() error {
|
||||
return closer.Close()
|
||||
}
|
||||
|
||||
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 WriteLog(src io.Reader, dst io.WriteCloser, format string) error {
|
||||
dec := json.NewDecoder(src)
|
||||
for {
|
||||
l := &JSONLog{}
|
||||
|
||||
if err := dec.Decode(l); err == io.EOF {
|
||||
return nil
|
||||
} else if err != nil {
|
||||
Errorf("Error streaming logs: %s", err)
|
||||
return err
|
||||
}
|
||||
line, err := l.Format(format)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintf(dst, "%s", line)
|
||||
}
|
||||
}
|
||||
|
||||
func GetTotalUsedFds() int {
|
||||
if fds, err := ioutil.ReadDir(fmt.Sprintf("/proc/%d/fd", os.Getpid())); err != nil {
|
||||
Errorf("Error opening /proc/%d/fd: %s", os.Getpid(), err)
|
||||
|
||||
Reference in New Issue
Block a user