From 92bf0a50460b7be1b7e0617ba7bf142f8d9fb680 Mon Sep 17 00:00:00 2001 From: John Howard Date: Wed, 20 Feb 2019 16:39:07 -0800 Subject: [PATCH] Windows:Add ETW logging hook Signed-off-by: John Howard --- cmd/dockerd/docker.go | 9 +-------- cmd/dockerd/docker_unix.go | 10 ++++++++++ cmd/dockerd/docker_windows.go | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) 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 +}