Просмотр исходного кода

enable syslog logger to have access to env and labels

Signed-off-by: Alan Scherger <flyinprogrammer@gmail.com>
Alan Scherger 9 лет назад
Родитель
Сommit
f67b711277
3 измененных файлов с 30 добавлено и 0 удалено
  1. 2 0
      daemon/logger/syslog/syslog.go
  2. 20 0
      docs/admin/logging/log_tags.md
  3. 8 0
      docs/admin/logging/overview.md

+ 2 - 0
daemon/logger/syslog/syslog.go

@@ -188,6 +188,8 @@ func parseAddress(address string) (string, string, error) {
 func ValidateLogOpt(cfg map[string]string) error {
 func ValidateLogOpt(cfg map[string]string) error {
 	for key := range cfg {
 	for key := range cfg {
 		switch key {
 		switch key {
+		case "env":
+		case "labels":
 		case "syslog-address":
 		case "syslog-address":
 		case "syslog-facility":
 		case "syslog-facility":
 		case "syslog-tag":
 		case "syslog-tag":

+ 20 - 0
docs/admin/logging/log_tags.md

@@ -46,6 +46,26 @@ For advanced usage, the generated tag's use [go
 templates](http://golang.org/pkg/text/template/) and the container's [logging
 templates](http://golang.org/pkg/text/template/) and the container's [logging
 context](https://github.com/docker/docker/blob/master/daemon/logger/context.go).
 context](https://github.com/docker/docker/blob/master/daemon/logger/context.go).
 
 
+As an example of what is possible with the syslog logger:
+
+```
+$ docker run -it --rm \
+    --log-driver syslog \
+    --log-opt tag="{{ (.ExtraAttributes nil).SOME_ENV_VAR }}" \
+    --log-opt env=SOME_ENV_VAR \
+    -e SOME_ENV_VAR=logtester.1234 \
+    flyinprogrammer/logtester
+```
+
+Results in logs like this:
+
+```
+Apr  1 15:22:17 ip-10-27-39-73 docker/logtester.1234[45499]: + exec app
+Apr  1 15:22:17 ip-10-27-39-73 docker/logtester.1234[45499]: 2016-04-01 15:22:17.075416751 +0000 UTC stderr msg: 1
+```
+
+
+
 >**Note**:The driver specific log options `syslog-tag`, `fluentd-tag` and
 >**Note**:The driver specific log options `syslog-tag`, `fluentd-tag` and
 >`gelf-tag` still work for backwards compatibility. However, going forward you
 >`gelf-tag` still work for backwards compatibility. However, going forward you
 >should standardize on using the generic `tag` log option instead.
 >should standardize on using the generic `tag` log option instead.

+ 8 - 0
docs/admin/logging/overview.md

@@ -81,6 +81,8 @@ The following logging options are supported for the `syslog` logging driver:
     --log-opt syslog-tls-skip-verify=true
     --log-opt syslog-tls-skip-verify=true
     --log-opt tag="mailer"
     --log-opt tag="mailer"
     --log-opt syslog-format=[rfc5424|rfc5424micro|rfc3164]
     --log-opt syslog-format=[rfc5424|rfc5424micro|rfc3164]
+    --log-opt env=ENV1,ENV2,ENV3
+    --log-opt labels=label1,label2,label3
 
 
 `syslog-address` specifies the remote syslog server address where the driver connects to.
 `syslog-address` specifies the remote syslog server address where the driver connects to.
 If not specified it defaults to the local unix socket of the running system.
 If not specified it defaults to the local unix socket of the running system.
@@ -128,6 +130,7 @@ This option is ignored if the address protocol is not `tcp+tls`.
 This verification is enabled by default, but it can be overriden by setting
 This verification is enabled by default, but it can be overriden by setting
 this option to `true`. This option is ignored if the address protocol is not `tcp+tls`.
 this option to `true`. This option is ignored if the address protocol is not `tcp+tls`.
 
 
+`tag` configures a string that is appended to the APP-NAME in the syslog message.
 By default, Docker uses the first 12 characters of the container ID to tag log messages.
 By default, Docker uses the first 12 characters of the container ID to tag log messages.
 Refer to the [log tag option documentation](log_tags.md) for customizing
 Refer to the [log tag option documentation](log_tags.md) for customizing
 the log tag format.
 the log tag format.
@@ -138,6 +141,11 @@ Specify rfc3164 to perform logging in RFC-3164 compatible format. Specify rfc542
 logging in RFC-5424 compatible format. Specify rfc5424micro to perform logging in RFC-5424
 logging in RFC-5424 compatible format. Specify rfc5424micro to perform logging in RFC-5424
 compatible format with microsecond timestamp resolution.
 compatible format with microsecond timestamp resolution.
 
 
+`env` should be a comma-separated list of keys of environment variables. Used for
+advanced [log tag options](log_tags.md).
+
+`labels` should be a comma-separated list of keys of labels. Used for advanced
+[log tag options](log_tags.md).
 
 
 ## journald options
 ## journald options