github.com/robertojrojas/docker@v1.9.1/docs/reference/logging/overview.md (about)

     1  <!--[metadata]>
     2  +++
     3  title = "Configuring Logging Drivers"
     4  description = "Configure logging driver."
     5  keywords = ["docker, logging, driver, Fluentd"]
     6  [menu.main]
     7  parent = "smn_logging"
     8  weight=-1
     9  +++
    10  <![end-metadata]-->
    11  
    12  
    13  # Configure logging drivers
    14  
    15  The container can have a different logging driver than the Docker daemon. Use
    16  the `--log-driver=VALUE` with the `docker run` command to configure the
    17  container's logging driver. The following options are supported:
    18  
    19  | `none`      | Disables any logging for the container. `docker logs` won't be available with this driver.                                    |
    20  |-------------|-------------------------------------------------------------------------------------------------------------------------------|
    21  | `json-file` | Default logging driver for Docker. Writes JSON messages to file.                                                              |
    22  | `syslog`    | Syslog logging driver for Docker. Writes log messages to syslog.                                                              |
    23  | `journald`  | Journald logging driver for Docker. Writes log messages to `journald`.                                                        |
    24  | `gelf`      | Graylog Extended Log Format (GELF) logging driver for Docker. Writes log messages to a GELF endpoint likeGraylog or Logstash. |
    25  | `fluentd`   | Fluentd logging driver for Docker. Writes log messages to `fluentd` (forward input).                                          |
    26  | `awslogs`   | Amazon CloudWatch Logs logging driver for Docker. Writes log messages to Amazon CloudWatch Logs.                              |
    27  
    28  The `docker logs`command is available only for the `json-file` logging driver.
    29  
    30  The `labels` and `env` options add additional attributes for use with logging drivers that accept them. Each option takes a comma-separated list of keys. If there is collision between `label` and `env` keys, the value of the `env` takes precedence.
    31  
    32  To use attributes, specify them when you start the Docker daemon.
    33  
    34  ```
    35  docker daemon --log-driver=json-file --log-opt labels=foo --log-opt env=foo,fizz
    36  ```
    37  
    38  Then, run a container and specify values for the `labels` or `env`.  For example, you might use this:
    39  
    40  ```
    41  docker run --label foo=bar -e fizz=buzz -d -P training/webapp python app.py
    42  ```
    43  
    44  This adds additional fields to the log depending on the driver, e.g. for
    45  `json-file` that looks like:
    46  
    47      "attrs":{"fizz":"buzz","foo":"bar"}
    48  
    49  
    50  ## json-file options
    51  
    52  The following logging options are supported for the `json-file` logging driver:
    53  
    54      --log-opt max-size=[0-9+][k|m|g]
    55      --log-opt max-file=[0-9+]
    56      --log-opt labels=label1,label2
    57      --log-opt env=env1,env2
    58  
    59  Logs that reach `max-size` are rolled over. You can set the size in kilobytes(k), megabytes(m), or gigabytes(g). eg `--log-opt max-size=50m`. If `max-size` is not set, then logs are not rolled over.
    60  
    61  `max-file` specifies the maximum number of files that a log is rolled over before being discarded. eg `--log-opt max-file=100`. If `max-size` is not set, then `max-file` is not honored.
    62  
    63  If `max-size` and `max-file` are set, `docker logs` only returns the log lines from the newest log file.
    64  
    65  
    66  ## syslog options
    67  
    68  The following logging options are supported for the `syslog` logging driver:
    69  
    70      --log-opt syslog-address=[tcp|udp]://host:port
    71      --log-opt syslog-address=unix://path
    72      --log-opt syslog-facility=daemon
    73      --log-opt tag="mailer"
    74  
    75  `syslog-address` specifies the remote syslog server address where the driver connects to.
    76  If not specified it defaults to the local unix socket of the running system.
    77  If transport is either `tcp` or `udp` and `port` is not specified it defaults to `514`
    78  The following example shows how to have the `syslog` driver connect to a `syslog`
    79  remote server at `192.168.0.42` on port `123`
    80  
    81      $ docker run --log-driver=syslog --log-opt syslog-address=tcp://192.168.0.42:123
    82  
    83  The `syslog-facility` option configures the syslog facility. By default, the system uses the
    84  `daemon` value. To override this behavior, you can provide an integer of 0 to 23 or any of
    85  the following named facilities:
    86  
    87  * `kern`
    88  * `user`
    89  * `mail`
    90  * `daemon`
    91  * `auth`
    92  * `syslog`
    93  * `lpr`
    94  * `news`
    95  * `uucp`
    96  * `cron`
    97  * `authpriv`
    98  * `ftp`
    99  * `local0`
   100  * `local1`
   101  * `local2`
   102  * `local3`
   103  * `local4`
   104  * `local5`
   105  * `local6`
   106  * `local7`
   107  
   108  By default, Docker uses the first 12 characters of the container ID to tag log messages.
   109  Refer to the [log tag option documentation](log_tags.md) for customizing
   110  the log tag format.
   111  
   112  
   113  ## journald options
   114  
   115  The `journald` logging driver stores the container id in the journal's `CONTAINER_ID` field. For detailed information on
   116  working with this logging driver, see [the journald logging driver](journald.md)
   117  reference documentation.
   118  
   119  ## gelf options
   120  
   121  The GELF logging driver supports the following options:
   122  
   123      --log-opt gelf-address=udp://host:port
   124      --log-opt tag="database"
   125      --log-opt labels=label1,label2
   126      --log-opt env=env1,env2
   127  
   128  The `gelf-address` option specifies the remote GELF server address that the
   129  driver connects to. Currently, only `udp` is supported as the transport and you must
   130  specify a `port` value. The following example shows how to connect the `gelf`
   131  driver to a GELF remote server at `192.168.0.42` on port `12201`
   132  
   133      $ docker run --log-driver=gelf --log-opt gelf-address=udp://192.168.0.42:12201
   134  
   135  By default, Docker uses the first 12 characters of the container ID to tag log messages.
   136  Refer to the [log tag option documentation](log_tags.md) for customizing
   137  the log tag format.
   138  
   139  The `labels` and `env` options are supported by the gelf logging
   140  driver. It adds additional key on the `extra` fields, prefixed by an
   141  underscore (`_`).
   142  
   143      // […]
   144      "_foo": "bar",
   145      "_fizz": "buzz",
   146      // […]
   147  
   148  
   149  ## fluentd options
   150  
   151  You can use the `--log-opt NAME=VALUE` flag to specify these additional Fluentd logging driver options.
   152  
   153   - `fluentd-address`: specify `host:port` to connect [localhost:24224]
   154   - `tag`: specify tag for `fluentd` message,
   155  
   156  For example, to specify both additional options:
   157  
   158  `docker run --log-driver=fluentd --log-opt fluentd-address=localhost:24224 --log-opt tag=docker.{{.Name}}`
   159  
   160  If container cannot connect to the Fluentd daemon on the specified address,
   161  the container stops immediately. For detailed information on working with this
   162  logging driver, see [the fluentd logging driver](fluentd.md)
   163  
   164  
   165  ## Specify Amazon CloudWatch Logs options
   166  
   167  The Amazon CloudWatch Logs logging driver supports the following options:
   168  
   169      --log-opt awslogs-region=<aws_region>
   170      --log-opt awslogs-group=<log_group_name>
   171      --log-opt awslogs-stream=<log_stream_name>
   172  
   173  
   174  For detailed information on working with this logging driver, see [the awslogs logging driver](awslogs.md) reference documentation.