ソースを参照

Windows:Add ETW logging hook

Signed-off-by: John Howard <jhoward@microsoft.com>
John Howard 6 年 前
コミット
92bf0a5046
3 ファイル変更27 行追加8 行削除
  1. 1 8
      cmd/dockerd/docker.go
  2. 10 0
      cmd/dockerd/docker_unix.go
  3. 16 0
      cmd/dockerd/docker_windows.go

+ 1 - 8
cmd/dockerd/docker.go

@@ -3,7 +3,6 @@ package main
 import (
 import (
 	"fmt"
 	"fmt"
 	"os"
 	"os"
-	"runtime"
 
 
 	"github.com/docker/docker/cli"
 	"github.com/docker/docker/cli"
 	"github.com/docker/docker/daemon/config"
 	"github.com/docker/docker/daemon/config"
@@ -70,13 +69,7 @@ func main() {
 	// Set terminal emulation based on platform as required.
 	// Set terminal emulation based on platform as required.
 	_, stdout, stderr := term.StdStreams()
 	_, 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) {
 	onError := func(err error) {
 		fmt.Fprintf(stderr, "%s\n", err)
 		fmt.Fprintf(stderr, "%s\n", err)

+ 10 - 0
cmd/dockerd/docker_unix.go

@@ -2,7 +2,17 @@
 
 
 package main
 package main
 
 
+import (
+	"io"
+
+	"github.com/sirupsen/logrus"
+)
+
 func runDaemon(opts *daemonOptions) error {
 func runDaemon(opts *daemonOptions) error {
 	daemonCli := NewDaemonCli()
 	daemonCli := NewDaemonCli()
 	return daemonCli.start(opts)
 	return daemonCli.start(opts)
 }
 }
+
+func initLogging(_, stderr io.Writer) {
+	logrus.SetOutput(stderr)
+}

+ 16 - 0
cmd/dockerd/docker_windows.go

@@ -1,8 +1,10 @@
 package main
 package main
 
 
 import (
 import (
+	"io"
 	"path/filepath"
 	"path/filepath"
 
 
+	"github.com/Microsoft/go-winio/pkg/etwlogrus"
 	_ "github.com/docker/docker/autogen/winresources/dockerd"
 	_ "github.com/docker/docker/autogen/winresources/dockerd"
 	"github.com/sirupsen/logrus"
 	"github.com/sirupsen/logrus"
 )
 )
@@ -36,3 +38,17 @@ func runDaemon(opts *daemonOptions) error {
 	notifyShutdown(err)
 	notifyShutdown(err)
 	return 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
+}