浏览代码

Allow disabling of colored Docker logs via daemon flag.

Signed-off-by: Vincent Woo <me@vincentwoo.com>
Signed-off-by: David Calavera <david.calavera@gmail.com>
Vincent Woo 9 年之前
父节点
当前提交
87a450a37f

+ 1 - 0
contrib/completion/bash/docker

@@ -748,6 +748,7 @@ _docker_daemon() {
 		--ip-masq=false
 		--ip-masq=false
 		--iptables=false
 		--iptables=false
 		--ipv6
 		--ipv6
+		--raw-logs
 		--selinux-enabled
 		--selinux-enabled
 		--userland-proxy=false
 		--userland-proxy=false
 	"
 	"

+ 1 - 0
contrib/completion/zsh/_docker

@@ -666,6 +666,7 @@ __docker_subcommand() {
                 "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_log_options" \
                 "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_log_options" \
                 "($help)--mtu=[Set the containers network MTU]:mtu:(0 576 1420 1500 9000)" \
                 "($help)--mtu=[Set the containers network MTU]:mtu:(0 576 1420 1500 9000)" \
                 "($help -p --pidfile)"{-p=,--pidfile=}"[Path to use for daemon PID file]:PID file:_files" \
                 "($help -p --pidfile)"{-p=,--pidfile=}"[Path to use for daemon PID file]:PID file:_files" \
+                "($help)--raw-logs[Full timestamps without ANSI coloring]" \
                 "($help)*--registry-mirror=[Preferred Docker registry mirror]:registry mirror: " \
                 "($help)*--registry-mirror=[Preferred Docker registry mirror]:registry mirror: " \
                 "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(aufs devicemapper btrfs zfs overlay)" \
                 "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(aufs devicemapper btrfs zfs overlay)" \
                 "($help)--selinux-enabled[Enable selinux support]" \
                 "($help)--selinux-enabled[Enable selinux support]" \

+ 1 - 1
contrib/init/upstart/docker.conf

@@ -39,7 +39,7 @@ script
 	if [ -f /etc/default/$UPSTART_JOB ]; then
 	if [ -f /etc/default/$UPSTART_JOB ]; then
 		. /etc/default/$UPSTART_JOB
 		. /etc/default/$UPSTART_JOB
 	fi
 	fi
-	exec "$DOCKER" daemon $DOCKER_OPTS
+	exec "$DOCKER" daemon $DOCKER_OPTS --raw-logs
 end script
 end script
 
 
 # Don't emit "started" event until docker.sock is ready.
 # Don't emit "started" event until docker.sock is ready.

+ 2 - 0
daemon/config.go

@@ -57,6 +57,7 @@ type CommonConfig struct {
 	Labels               []string            `json:"labels,omitempty"`
 	Labels               []string            `json:"labels,omitempty"`
 	Mtu                  int                 `json:"mtu,omitempty"`
 	Mtu                  int                 `json:"mtu,omitempty"`
 	Pidfile              string              `json:"pidfile,omitempty"`
 	Pidfile              string              `json:"pidfile,omitempty"`
+	RawLogs              bool                `json:"raw-logs,omitempty"`
 	Root                 string              `json:"graph,omitempty"`
 	Root                 string              `json:"graph,omitempty"`
 	TrustKeyPath         string              `json:"-"`
 	TrustKeyPath         string              `json:"-"`
 
 
@@ -104,6 +105,7 @@ func (config *Config) InstallCommonFlags(cmd *flag.FlagSet, usageFn func(string)
 	cmd.BoolVar(&config.AutoRestart, []string{"#r", "#-restart"}, true, usageFn("--restart on the daemon has been deprecated in favor of --restart policies on docker run"))
 	cmd.BoolVar(&config.AutoRestart, []string{"#r", "#-restart"}, true, usageFn("--restart on the daemon has been deprecated in favor of --restart policies on docker run"))
 	cmd.StringVar(&config.GraphDriver, []string{"s", "-storage-driver"}, "", usageFn("Storage driver to use"))
 	cmd.StringVar(&config.GraphDriver, []string{"s", "-storage-driver"}, "", usageFn("Storage driver to use"))
 	cmd.IntVar(&config.Mtu, []string{"#mtu", "-mtu"}, 0, usageFn("Set the containers network MTU"))
 	cmd.IntVar(&config.Mtu, []string{"#mtu", "-mtu"}, 0, usageFn("Set the containers network MTU"))
+	cmd.BoolVar(&config.RawLogs, []string{"-raw-logs"}, false, usageFn("Full timestamps without ANSI coloring"))
 	// FIXME: why the inconsistency between "hosts" and "sockets"?
 	// FIXME: why the inconsistency between "hosts" and "sockets"?
 	cmd.Var(opts.NewListOptsRef(&config.DNS, opts.ValidateIPAddress), []string{"#dns", "-dns"}, usageFn("DNS server to use"))
 	cmd.Var(opts.NewListOptsRef(&config.DNS, opts.ValidateIPAddress), []string{"#dns", "-dns"}, usageFn("DNS server to use"))
 	cmd.Var(opts.NewNamedListOptsRef("dns-opts", &config.DNSOptions, nil), []string{"-dns-opt"}, usageFn("DNS options to use"))
 	cmd.Var(opts.NewNamedListOptsRef("dns-opts", &config.DNSOptions, nil), []string{"-dns-opt"}, usageFn("DNS options to use"))

+ 4 - 1
docker/daemon.go

@@ -168,7 +168,10 @@ func (cli *DaemonCli) CmdDaemon(args ...string) error {
 		logrus.Warn("Running experimental build")
 		logrus.Warn("Running experimental build")
 	}
 	}
 
 
-	logrus.SetFormatter(&logrus.TextFormatter{TimestampFormat: jsonlog.RFC3339NanoFixed})
+	logrus.SetFormatter(&logrus.TextFormatter{
+		TimestampFormat: jsonlog.RFC3339NanoFixed,
+		DisableColors:   cli.Config.RawLogs,
+	})
 
 
 	if err := setDefaultUmask(); err != nil {
 	if err := setDefaultUmask(); err != nil {
 		logrus.Fatalf("Failed to set umask: %v", err)
 		logrus.Fatalf("Failed to set umask: %v", err)

+ 15 - 13
docs/reference/commandline/daemon.md

@@ -54,6 +54,7 @@ weight = -1
       --mtu=0                                Set the containers network MTU
       --mtu=0                                Set the containers network MTU
       --disable-legacy-registry              Do not contact legacy registries
       --disable-legacy-registry              Do not contact legacy registries
       -p, --pidfile="/var/run/docker.pid"    Path to use for daemon PID file
       -p, --pidfile="/var/run/docker.pid"    Path to use for daemon PID file
+      --raw-logs                             Full timestamps without ANSI coloring
       --registry-mirror=[]                   Preferred Docker registry mirror
       --registry-mirror=[]                   Preferred Docker registry mirror
       -s, --storage-driver=""                Storage driver to use
       -s, --storage-driver=""                Storage driver to use
       --selinux-enabled                      Enable selinux support
       --selinux-enabled                      Enable selinux support
@@ -860,19 +861,20 @@ This is a full example of the allowed configuration options in the file:
 	"group": "",
 	"group": "",
 	"cgroup-parent": "",
 	"cgroup-parent": "",
 	"default-ulimits": {},
 	"default-ulimits": {},
-       "ipv6": false,
-       "iptables": false,
-       "ip-forward": false,
-       "ip-mask": false,
-       "userland-proxy": false,
-       "ip": "0.0.0.0",
-       "bridge": "",
-       "bip": "",
-       "fixed-cidr": "",
-       "fixed-cidr-v6": "",
-       "default-gateway": "",
-       "default-gateway-v6": "",
-       "icc": false
+	"ipv6": false,
+	"iptables": false,
+	"ip-forward": false,
+	"ip-mask": false,
+	"userland-proxy": false,
+	"ip": "0.0.0.0",
+	"bridge": "",
+	"bip": "",
+	"fixed-cidr": "",
+	"fixed-cidr-v6": "",
+	"default-gateway": "",
+	"default-gateway-v6": "",
+	"icc": false,
+	"raw-logs": false
 }
 }
 ```
 ```
 
 

+ 6 - 0
man/docker-daemon.8.md

@@ -44,6 +44,7 @@ docker-daemon - Enable daemon mode
 [**--log-opt**[=*map[]*]]
 [**--log-opt**[=*map[]*]]
 [**--mtu**[=*0*]]
 [**--mtu**[=*0*]]
 [**-p**|**--pidfile**[=*/var/run/docker.pid*]]
 [**-p**|**--pidfile**[=*/var/run/docker.pid*]]
+[**--raw-logs**]
 [**--registry-mirror**[=*[]*]]
 [**--registry-mirror**[=*[]*]]
 [**-s**|**--storage-driver**[=*STORAGE-DRIVER*]]
 [**-s**|**--storage-driver**[=*STORAGE-DRIVER*]]
 [**--selinux-enabled**]
 [**--selinux-enabled**]
@@ -197,6 +198,11 @@ unix://[/path/to/socket] to use.
 **-p**, **--pidfile**=""
 **-p**, **--pidfile**=""
   Path to use for daemon PID file. Default is `/var/run/docker.pid`
   Path to use for daemon PID file. Default is `/var/run/docker.pid`
 
 
+**--raw-logs**
+Output daemon logs in full timestamp format without ANSI coloring. If this flag is not set,
+the daemon outputs condensed, colorized logs if a terminal is detected, or full ("raw")
+output otherwise.
+
 **--registry-mirror**=*<scheme>://<host>*
 **--registry-mirror**=*<scheme>://<host>*
   Prepend a registry mirror to be used for image pulls. May be specified multiple times.
   Prepend a registry mirror to be used for image pulls. May be specified multiple times.