Replace glog with logrus
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
@@ -23,7 +23,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/containerd/containerd/cio"
|
||||
"github.com/golang/glog"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
cioutil "github.com/containerd/cri-containerd/pkg/ioutil"
|
||||
"github.com/containerd/cri-containerd/pkg/util"
|
||||
@@ -125,24 +125,24 @@ func (c *ContainerIO) Pipe() {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
if _, err := io.Copy(c.stdoutGroup, c.stdout); err != nil {
|
||||
glog.Errorf("Failed to pipe stdout of container %q: %v", c.id, err)
|
||||
logrus.WithError(err).Errorf("Failed to pipe stdout of container %q", c.id)
|
||||
}
|
||||
c.stdout.Close()
|
||||
c.stdoutGroup.Close()
|
||||
wg.Done()
|
||||
glog.V(2).Infof("Finish piping stdout of container %q", c.id)
|
||||
logrus.Infof("Finish piping stdout of container %q", c.id)
|
||||
}()
|
||||
|
||||
if !c.fifos.Terminal {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
if _, err := io.Copy(c.stderrGroup, c.stderr); err != nil {
|
||||
glog.Errorf("Failed to pipe stderr of container %q: %v", c.id, err)
|
||||
logrus.WithError(err).Errorf("Failed to pipe stderr of container %q", c.id)
|
||||
}
|
||||
c.stderr.Close()
|
||||
c.stderrGroup.Close()
|
||||
wg.Done()
|
||||
glog.V(2).Infof("Finish piping stderr of container %q", c.id)
|
||||
logrus.Infof("Finish piping stderr of container %q", c.id)
|
||||
}()
|
||||
}
|
||||
}
|
||||
@@ -165,9 +165,9 @@ func (c *ContainerIO) Attach(opts AttachOptions) error {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
if _, err := io.Copy(c.stdin, stdinStreamRC); err != nil {
|
||||
glog.Errorf("Failed to pipe stdin for container attach %q: %v", c.id, err)
|
||||
logrus.WithError(err).Errorf("Failed to pipe stdin for container attach %q", c.id)
|
||||
}
|
||||
glog.V(2).Infof("Attach stream %q closed", stdinKey)
|
||||
logrus.Infof("Attach stream %q closed", stdinKey)
|
||||
if opts.StdinOnce && !opts.Tty {
|
||||
// Due to kubectl requirements and current docker behavior, when (opts.StdinOnce &&
|
||||
// opts.Tty) we have to close container stdin and keep stdout and stderr open until
|
||||
@@ -175,7 +175,7 @@ func (c *ContainerIO) Attach(opts AttachOptions) error {
|
||||
c.stdin.Close()
|
||||
// Also closes the containerd side.
|
||||
if err := opts.CloseStdin(); err != nil {
|
||||
glog.Errorf("Failed to close stdin for container %q: %v", c.id, err)
|
||||
logrus.WithError(err).Errorf("Failed to close stdin for container %q", c.id)
|
||||
}
|
||||
} else {
|
||||
if opts.Stdout != nil {
|
||||
@@ -191,7 +191,7 @@ func (c *ContainerIO) Attach(opts AttachOptions) error {
|
||||
|
||||
attachStream := func(key string, close <-chan struct{}) {
|
||||
<-close
|
||||
glog.V(2).Infof("Attach stream %q closed", key)
|
||||
logrus.Infof("Attach stream %q closed", key)
|
||||
// Make sure stdin gets closed.
|
||||
if stdinStreamRC != nil {
|
||||
stdinStreamRC.Close()
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/containerd/containerd/cio"
|
||||
"github.com/golang/glog"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
cioutil "github.com/containerd/cri-containerd/pkg/ioutil"
|
||||
)
|
||||
@@ -68,13 +68,13 @@ func (e *ExecIO) Attach(opts AttachOptions) <-chan struct{} {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
if _, err := io.Copy(e.stdin, stdinStreamRC); err != nil {
|
||||
glog.Errorf("Failed to redirect stdin for container exec %q: %v", e.id, err)
|
||||
logrus.WithError(err).Errorf("Failed to redirect stdin for container exec %q", e.id)
|
||||
}
|
||||
glog.V(2).Infof("Container exec %q stdin closed", e.id)
|
||||
logrus.Infof("Container exec %q stdin closed", e.id)
|
||||
if opts.StdinOnce && !opts.Tty {
|
||||
e.stdin.Close()
|
||||
if err := opts.CloseStdin(); err != nil {
|
||||
glog.Errorf("Failed to close stdin for container exec %q: %v", e.id, err)
|
||||
logrus.WithError(err).Errorf("Failed to close stdin for container exec %q", e.id)
|
||||
}
|
||||
} else {
|
||||
if e.stdout != nil {
|
||||
@@ -90,7 +90,7 @@ func (e *ExecIO) Attach(opts AttachOptions) <-chan struct{} {
|
||||
|
||||
attachOutput := func(t StreamType, stream io.WriteCloser, out io.ReadCloser) {
|
||||
if _, err := io.Copy(stream, out); err != nil {
|
||||
glog.Errorf("Failed to pipe %q for container exec %q: %v", t, e.id, err)
|
||||
logrus.WithError(err).Errorf("Failed to pipe %q for container exec %q", t, e.id)
|
||||
}
|
||||
out.Close()
|
||||
stream.Close()
|
||||
@@ -99,7 +99,7 @@ func (e *ExecIO) Attach(opts AttachOptions) <-chan struct{} {
|
||||
}
|
||||
e.closer.wg.Done()
|
||||
wg.Done()
|
||||
glog.V(2).Infof("Finish piping %q of container exec %q", t, e.id)
|
||||
logrus.Infof("Finish piping %q of container exec %q", t, e.id)
|
||||
}
|
||||
|
||||
if opts.Stdout != nil {
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/sirupsen/logrus"
|
||||
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
||||
|
||||
cioutil "github.com/containerd/cri-containerd/pkg/ioutil"
|
||||
@@ -53,7 +53,7 @@ func NewDiscardLogger() io.WriteCloser {
|
||||
// NewCRILogger returns a write closer which redirect container log into
|
||||
// log file, and decorate the log line into CRI defined format.
|
||||
func NewCRILogger(path string, stream StreamType) (io.WriteCloser, error) {
|
||||
glog.V(4).Infof("Start writing log file %q", path)
|
||||
logrus.Debugf("Start writing log file %q", path)
|
||||
prc, pwc := io.Pipe()
|
||||
f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0640)
|
||||
if err != nil {
|
||||
@@ -74,11 +74,11 @@ func redirectLogs(path string, rc io.ReadCloser, wc io.WriteCloser, stream Strea
|
||||
for {
|
||||
lineBytes, isPrefix, err := r.ReadLine()
|
||||
if err == io.EOF {
|
||||
glog.V(4).Infof("Finish redirecting log file %q", path)
|
||||
logrus.Debugf("Finish redirecting log file %q", path)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
glog.Errorf("An error occurred when redirecting log file %q: %v", path, err)
|
||||
logrus.WithError(err).Errorf("An error occurred when redirecting log file %q", path)
|
||||
return
|
||||
}
|
||||
tagBytes := fullBytes
|
||||
@@ -89,7 +89,7 @@ func redirectLogs(path string, rc io.ReadCloser, wc io.WriteCloser, stream Strea
|
||||
data := bytes.Join([][]byte{timestampBytes, streamBytes, tagBytes, lineBytes}, delimiterBytes)
|
||||
data = append(data, eol)
|
||||
if _, err := wc.Write(data); err != nil {
|
||||
glog.Errorf("Fail to write %q log to log file %q: %v", stream, path, err)
|
||||
logrus.WithError(err).Errorf("Fail to write %q log to log file %q", stream, path)
|
||||
}
|
||||
// Continue on write error to drain the input.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user