github.com/portworx/docker@v1.12.1/docs/admin/logging/log_tags.md (about)

     1  <!--[metadata]>
     2  +++
     3  aliases = ["/engine/reference/logging/log_tags/"]
     4  title = "Log tags for logging driver"
     5  description = "Describes how to format tags for."
     6  keywords = ["docker, logging, driver, syslog, Fluentd, gelf, journald"]
     7  [menu.main]
     8  parent = "smn_logging"
     9  weight = -1
    10  +++
    11  <![end-metadata]-->
    12  
    13  # Log Tags
    14  
    15  The `tag` log option specifies how to format a tag that identifies the
    16  container's log messages. By default, the system uses the first 12 characters of
    17  the container id. To override this behavior, specify a `tag` option:
    18  
    19  ```
    20  docker run --log-driver=fluentd --log-opt fluentd-address=myhost.local:24224 --log-opt tag="mailer"
    21  ```
    22  
    23  Docker supports some special template markup you can use when specifying a tag's value:
    24  
    25  | Markup             | Description                                          |
    26  |--------------------|------------------------------------------------------|
    27  | `{{.ID}}`          | The first 12 characters of the container id.         |
    28  | `{{.FullID}}`      | The full container id.                               |
    29  | `{{.Name}}`        | The container name.                                  |
    30  | `{{.ImageID}}`     | The first 12 characters of the container's image id. |
    31  | `{{.ImageFullID}}` | The container's full image identifier.               |
    32  | `{{.ImageName}}`   | The name of the image used by the container.         |
    33  | `{{.DaemonName}}`  | The name of the docker program (`docker`).           |
    34  
    35  For example, specifying a `--log-opt tag="{{.ImageName}}/{{.Name}}/{{.ID}}"` value yields `syslog` log lines like:
    36  
    37  ```
    38  Aug  7 18:33:19 HOSTNAME docker/hello-world/foobar/5790672ab6a0[9103]: Hello from Docker.
    39  ```
    40  
    41  At startup time, the system sets the `container_name` field and `{{.Name}}` in
    42  the tags. If you use `docker rename` to rename a container, the new name is not
    43  reflected in the log messages. Instead, these messages continue to use the
    44  original container name.
    45  
    46  For advanced usage, the generated tag's use [go
    47  templates](http://golang.org/pkg/text/template/) and the container's [logging
    48  context](https://github.com/docker/docker/blob/master/daemon/logger/context.go).
    49  
    50  As an example of what is possible with the syslog logger:
    51  
    52  ```
    53  $ docker run -it --rm \
    54      --log-driver syslog \
    55      --log-opt tag="{{ (.ExtraAttributes nil).SOME_ENV_VAR }}" \
    56      --log-opt env=SOME_ENV_VAR \
    57      -e SOME_ENV_VAR=logtester.1234 \
    58      flyinprogrammer/logtester
    59  ```
    60  
    61  Results in logs like this:
    62  
    63  ```
    64  Apr  1 15:22:17 ip-10-27-39-73 docker/logtester.1234[45499]: + exec app
    65  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
    66  ```
    67