diff --git a/cmd/dockerd/docker.go b/cmd/dockerd/docker.go index a6d3387828..4b4f5acdea 100644 --- a/cmd/dockerd/docker.go +++ b/cmd/dockerd/docker.go @@ -3,7 +3,6 @@ package main import ( "fmt" "os" - "runtime" "github.com/docker/docker/cli" "github.com/docker/docker/daemon/config" @@ -70,13 +69,7 @@ func main() { // Set terminal emulation based on platform as required. _, stdout, stderr := term.StdStreams() - // @jhowardmsft - maybe there is a historic reason why on non-Windows, stderr is used - // here. However, on Windows it makes no sense and there is no need. - if runtime.GOOS == "windows" { - logrus.SetOutput(stdout) - } else { - logrus.SetOutput(stderr) - } + initLogging(stdout, stderr) onError := func(err error) { fmt.Fprintf(stderr, "%s\n", err) diff --git a/cmd/dockerd/docker_unix.go b/cmd/dockerd/docker_unix.go index 0dec48663d..5165af775a 100644 --- a/cmd/dockerd/docker_unix.go +++ b/cmd/dockerd/docker_unix.go @@ -2,7 +2,17 @@ package main +import ( + "io" + + "github.com/sirupsen/logrus" +) + func runDaemon(opts *daemonOptions) error { daemonCli := NewDaemonCli() return daemonCli.start(opts) } + +func initLogging(_, stderr io.Writer) { + logrus.SetOutput(stderr) +} diff --git a/cmd/dockerd/docker_windows.go b/cmd/dockerd/docker_windows.go index bd8bc5a58e..a9e942a38b 100644 --- a/cmd/dockerd/docker_windows.go +++ b/cmd/dockerd/docker_windows.go @@ -1,8 +1,10 @@ package main import ( + "io" "path/filepath" + "github.com/Microsoft/go-winio/pkg/etwlogrus" _ "github.com/docker/docker/autogen/winresources/dockerd" "github.com/sirupsen/logrus" ) @@ -36,3 +38,17 @@ func runDaemon(opts *daemonOptions) error { notifyShutdown(err) return err } + +func initLogging(stdout, _ io.Writer) { + // Maybe there is a historic reason why on non-Windows, stderr is used + // for output. However, on Windows it makes no sense and there is no need. + logrus.SetOutput(stdout) + + // Provider ID: {6996f090-c5de-5082-a81e-5841acc3a635} + // Hook isn't closed explicitly, as it will exist until process exit. + // GUID is generated based on name - see Microsoft/go-winio/tools/etw-provider-gen. + if hook, err := etwlogrus.NewHook("Moby"); err == nil { + logrus.AddHook(hook) + } + return +}