github.com/hustcat/docker@v1.3.3-0.20160314103604-901c67a8eeab/docs/admin/logging/overview.md (about)

     1  <!--[metadata]>
     2  +++
     3  aliases = ["/engine/reference/logging/overview/"]
     4  title = "Configuring Logging Drivers"
     5  description = "Configure logging driver."
     6  keywords = ["docker, logging, driver, Fluentd"]
     7  [menu.main]
     8  parent = "smn_logging"
     9  weight=-1
    10  +++
    11  <![end-metadata]-->
    12  
    13  
    14  # Configure logging drivers
    15  
    16  The container can have a different logging driver than the Docker daemon. Use
    17  the `--log-driver=VALUE` with the `docker run` command to configure the
    18  container's logging driver. The following options are supported:
    19  
    20  | `none`      | Disables any logging for the container. `docker logs` won't be available with this driver.                                    |
    21  |-------------|-------------------------------------------------------------------------------------------------------------------------------|
    22  | `json-file` | Default logging driver for Docker. Writes JSON messages to file.                                                              |
    23  | `syslog`    | Syslog logging driver for Docker. Writes log messages to syslog.                                                              |
    24  | `journald`  | Journald logging driver for Docker. Writes log messages to `journald`.                                                        |
    25  | `gelf`      | Graylog Extended Log Format (GELF) logging driver for Docker. Writes log messages to a GELF endpoint likeGraylog or Logstash. |
    26  | `fluentd`   | Fluentd logging driver for Docker. Writes log messages to `fluentd` (forward input).                                          |
    27  | `awslogs`   | Amazon CloudWatch Logs logging driver for Docker. Writes log messages to Amazon CloudWatch Logs.                              |
    28  | `splunk`    | Splunk logging driver for Docker. Writes log messages to `splunk` using HTTP Event Collector.                                 |
    29  | `etwlogs`   | ETW logging driver for Docker on Windows. Writes log messages as ETW events.                                                  |
    30  | `gcplogs`   | Google Cloud Logging driver for Docker. Writes log messages to Google Cloud Logging.                                          |
    31  
    32  The `docker logs`command is available only for the `json-file` and `journald`
    33  logging drivers.
    34  
    35  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.
    36  
    37  To use attributes, specify them when you start the Docker daemon.
    38  
    39  ```
    40  docker daemon --log-driver=json-file --log-opt labels=foo --log-opt env=foo,fizz
    41  ```
    42  
    43  Then, run a container and specify values for the `labels` or `env`.  For example, you might use this:
    44  
    45  ```
    46  docker run --label foo=bar -e fizz=buzz -d -P training/webapp python app.py
    47  ```
    48  
    49  This adds additional fields to the log depending on the driver, e.g. for
    50  `json-file` that looks like:
    51  
    52      "attrs":{"fizz":"buzz","foo":"bar"}
    53  
    54  
    55  ## json-file options
    56  
    57  The following logging options are supported for the `json-file` logging driver:
    58  
    59      --log-opt max-size=[0-9+][k|m|g]
    60      --log-opt max-file=[0-9+]
    61      --log-opt labels=label1,label2
    62      --log-opt env=env1,env2
    63  
    64  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.
    65  
    66  `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.
    67  
    68  If `max-size` and `max-file` are set, `docker logs` only returns the log lines from the newest log file.
    69  
    70  
    71  ## syslog options
    72  
    73  The following logging options are supported for the `syslog` logging driver:
    74  
    75      --log-opt syslog-address=[tcp|udp|tcp+tls]://host:port
    76      --log-opt syslog-address=unix://path
    77      --log-opt syslog-facility=daemon
    78      --log-opt syslog-tls-ca-cert=/etc/ca-certificates/custom/ca.pem
    79      --log-opt syslog-tls-cert=/etc/ca-certificates/custom/cert.pem
    80      --log-opt syslog-tls-key=/etc/ca-certificates/custom/key.pem
    81      --log-opt syslog-tls-skip-verify=true
    82      --log-opt tag="mailer"
    83  
    84  `syslog-address` specifies the remote syslog server address where the driver connects to.
    85  If not specified it defaults to the local unix socket of the running system.
    86  If transport is either `tcp` or `udp` and `port` is not specified it defaults to `514`
    87  The following example shows how to have the `syslog` driver connect to a `syslog`
    88  remote server at `192.168.0.42` on port `123`
    89  
    90      $ docker run --log-driver=syslog --log-opt syslog-address=tcp://192.168.0.42:123
    91  
    92  The `syslog-facility` option configures the syslog facility. By default, the system uses the
    93  `daemon` value. To override this behavior, you can provide an integer of 0 to 23 or any of
    94  the following named facilities:
    95  
    96  * `kern`
    97  * `user`
    98  * `mail`
    99  * `daemon`
   100  * `auth`
   101  * `syslog`
   102  * `lpr`
   103  * `news`
   104  * `uucp`
   105  * `cron`
   106  * `authpriv`
   107  * `ftp`
   108  * `local0`
   109  * `local1`
   110  * `local2`
   111  * `local3`
   112  * `local4`
   113  * `local5`
   114  * `local6`
   115  * `local7`
   116  
   117  `syslog-tls-ca-cert` specifies the absolute path to the trust certificates
   118  signed by the CA. This option is ignored if the address protocol is not `tcp+tls`.
   119  
   120  `syslog-tls-cert` specifies the absolute path to the TLS certificate file.
   121  This option is ignored if the address protocol is not `tcp+tls`.
   122  
   123  `syslog-tls-key` specifies the absolute path to the TLS key file.
   124  This option is ignored if the address protocol is not `tcp+tls`.
   125  
   126  `syslog-tls-skip-verify` configures the TLS verification.
   127  This verification is enabled by default, but it can be overriden by setting
   128  this option to `true`. This option is ignored if the address protocol is not `tcp+tls`.
   129  
   130  By default, Docker uses the first 12 characters of the container ID to tag log messages.
   131  Refer to the [log tag option documentation](log_tags.md) for customizing
   132  the log tag format.
   133  
   134  
   135  ## journald options
   136  
   137  The `journald` logging driver stores the container id in the journal's `CONTAINER_ID` field. For detailed information on
   138  working with this logging driver, see [the journald logging driver](journald.md)
   139  reference documentation.
   140  
   141  ## gelf options
   142  
   143  The GELF logging driver supports the following options:
   144  
   145      --log-opt gelf-address=udp://host:port
   146      --log-opt tag="database"
   147      --log-opt labels=label1,label2
   148      --log-opt env=env1,env2
   149  
   150  The `gelf-address` option specifies the remote GELF server address that the
   151  driver connects to. Currently, only `udp` is supported as the transport and you must
   152  specify a `port` value. The following example shows how to connect the `gelf`
   153  driver to a GELF remote server at `192.168.0.42` on port `12201`
   154  
   155      $ docker run --log-driver=gelf --log-opt gelf-address=udp://192.168.0.42:12201
   156  
   157  By default, Docker uses the first 12 characters of the container ID to tag log messages.
   158  Refer to the [log tag option documentation](log_tags.md) for customizing
   159  the log tag format.
   160  
   161  The `labels` and `env` options are supported by the gelf logging
   162  driver. It adds additional key on the `extra` fields, prefixed by an
   163  underscore (`_`).
   164  
   165      // […]
   166      "_foo": "bar",
   167      "_fizz": "buzz",
   168      // […]
   169  
   170  
   171  ## fluentd options
   172  
   173  You can use the `--log-opt NAME=VALUE` flag to specify these additional Fluentd logging driver options.
   174  
   175   - `fluentd-address`: specify `host:port` to connect [localhost:24224]
   176   - `tag`: specify tag for `fluentd` message,
   177   - `fail-on-startup-error`: true/false; Should the logging driver fail container startup in case of connect error during startup. Default: true (backwards compatible)
   178   - `buffer-limit`: Size limit (bytes) for the buffer which is used to buffer messages in case of connection outages. Default: 1M
   179  
   180  For example, to specify both additional options:
   181  
   182  `docker run --log-driver=fluentd --log-opt fluentd-address=localhost:24224 --log-opt tag=docker.{{.Name}}`
   183  
   184  If container cannot connect to the Fluentd daemon on the specified address,
   185  the container stops immediately. For detailed information on working with this
   186  logging driver, see [the fluentd logging driver](fluentd.md)
   187  
   188  
   189  ## Specify Amazon CloudWatch Logs options
   190  
   191  The Amazon CloudWatch Logs logging driver supports the following options:
   192  
   193      --log-opt awslogs-region=<aws_region>
   194      --log-opt awslogs-group=<log_group_name>
   195      --log-opt awslogs-stream=<log_stream_name>
   196  
   197  
   198  For detailed information on working with this logging driver, see [the awslogs logging driver](awslogs.md) reference documentation.
   199  
   200  ## Splunk options
   201  
   202  The Splunk logging driver requires the following options:
   203  
   204      --log-opt splunk-token=<splunk_http_event_collector_token>
   205      --log-opt splunk-url=https://your_splunk_instance:8088
   206  
   207  For detailed information about working with this logging driver, see the [Splunk logging driver](splunk.md)
   208  reference documentation.
   209  
   210  ## ETW logging driver options
   211  
   212  The etwlogs logging driver does not require any options to be specified. This logging driver will forward each log message
   213  as an ETW event. An ETW listener can then be created to listen for these events. 
   214  
   215  For detailed information on working with this logging driver, see [the ETW logging driver](etwlogs.md) reference documentation.
   216  
   217  ## Google Cloud Logging
   218  
   219  The Google Cloud Logging driver supports the following options:
   220  
   221      --log-opt gcp-project=<gcp_projext>
   222      --log-opt labels=<label1>,<label2>
   223      --log-opt env=<envvar1>,<envvar2>
   224      --log-opt log-cmd=true
   225  
   226  For detailed information about working with this logging driver, see the [Google Cloud Logging driver](gcplogs.md).
   227  reference documentation.