Преглед на файлове

cmd/dockerd/trap: log to logrus directly

Logging through a dependency-injected interface value was a vestige of
when Trap was in pkg/signal to avoid importing logrus in a reusable
package: cc4da8112814cdbb00dbf23370f9ed764383de1f.
Now that Trap lives under cmd/dockerd, nobody will be importing this so
we no longer need to worry about minimizing the package's dependencies.

Signed-off-by: Cory Snider <csnider@mirantis.com>
Cory Snider преди 2 години
родител
ревизия
993ca8c6de
променени са 3 файла, в които са добавени 7 реда и са изтрити 9 реда
  1. 1 1
      cmd/dockerd/daemon.go
  2. 1 2
      cmd/dockerd/trap/testfiles/main.go
  3. 5 6
      cmd/dockerd/trap/trap.go

+ 1 - 1
cmd/dockerd/daemon.go

@@ -183,7 +183,7 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
 	trap.Trap(func() {
 		cli.stop()
 		<-stopc // wait for daemonCli.start() to return
-	}, logrus.StandardLogger())
+	})
 
 	// Notify that the API is active, but before daemon is set up.
 	preNotifyReady()

+ 1 - 2
cmd/dockerd/trap/testfiles/main.go

@@ -6,7 +6,6 @@ import (
 	"time"
 
 	"github.com/docker/docker/cmd/dockerd/trap"
-	"github.com/sirupsen/logrus"
 )
 
 func main() {
@@ -18,7 +17,7 @@ func main() {
 	trap.Trap(func() {
 		time.Sleep(time.Second)
 		os.Exit(99)
-	}, logrus.StandardLogger())
+	})
 	go func() {
 		p, err := os.FindProcess(os.Getpid())
 		if err != nil {

+ 5 - 6
cmd/dockerd/trap/trap.go

@@ -1,10 +1,11 @@
 package trap // import "github.com/docker/docker/cmd/dockerd/trap"
 
 import (
-	"fmt"
 	"os"
 	"os/signal"
 	"syscall"
+
+	"github.com/sirupsen/logrus"
 )
 
 const (
@@ -22,15 +23,13 @@ const (
 //
 // If SIGINT or SIGTERM are received 3 times, the process is terminated
 // immediately with an exit code of 128 + the signal number.
-func Trap(cleanup func(), logger interface {
-	Info(args ...interface{})
-}) {
+func Trap(cleanup func()) {
 	c := make(chan os.Signal, forceQuitCount)
 	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
 	go func() {
 		var interruptCount int
 		for sig := range c {
-			logger.Info(fmt.Sprintf("Processing signal '%v'", sig))
+			logrus.Infof("Processing signal '%v'", sig)
 			if interruptCount < forceQuitCount {
 				interruptCount++
 				// Initiate the cleanup only once
@@ -40,7 +39,7 @@ func Trap(cleanup func(), logger interface {
 				continue
 			}
 
-			logger.Info("Forcing docker daemon shutdown without cleanup; 3 interrupts received")
+			logrus.Info("Forcing docker daemon shutdown without cleanup; 3 interrupts received")
 			os.Exit(128 + int(sig.(syscall.Signal)))
 		}
 	}()