github.com/boynux/docker@v1.11.0-rc4/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 --log-opt syslog-format=[rfc5424|rfc3164] 84 85 `syslog-address` specifies the remote syslog server address where the driver connects to. 86 If not specified it defaults to the local unix socket of the running system. 87 If transport is either `tcp` or `udp` and `port` is not specified it defaults to `514` 88 The following example shows how to have the `syslog` driver connect to a `syslog` 89 remote server at `192.168.0.42` on port `123` 90 91 $ docker run --log-driver=syslog --log-opt syslog-address=tcp://192.168.0.42:123 92 93 The `syslog-facility` option configures the syslog facility. By default, the system uses the 94 `daemon` value. To override this behavior, you can provide an integer of 0 to 23 or any of 95 the following named facilities: 96 97 * `kern` 98 * `user` 99 * `mail` 100 * `daemon` 101 * `auth` 102 * `syslog` 103 * `lpr` 104 * `news` 105 * `uucp` 106 * `cron` 107 * `authpriv` 108 * `ftp` 109 * `local0` 110 * `local1` 111 * `local2` 112 * `local3` 113 * `local4` 114 * `local5` 115 * `local6` 116 * `local7` 117 118 `syslog-tls-ca-cert` specifies the absolute path to the trust certificates 119 signed by the CA. This option is ignored if the address protocol is not `tcp+tls`. 120 121 `syslog-tls-cert` specifies the absolute path to the TLS certificate file. 122 This option is ignored if the address protocol is not `tcp+tls`. 123 124 `syslog-tls-key` specifies the absolute path to the TLS key file. 125 This option is ignored if the address protocol is not `tcp+tls`. 126 127 `syslog-tls-skip-verify` configures the TLS verification. 128 This verification is enabled by default, but it can be overriden by setting 129 this option to `true`. This option is ignored if the address protocol is not `tcp+tls`. 130 131 By default, Docker uses the first 12 characters of the container ID to tag log messages. 132 Refer to the [log tag option documentation](log_tags.md) for customizing 133 the log tag format. 134 135 `syslog-format` specifies syslog message format to use when logging. 136 If not specified it defaults to the local unix syslog format without hostname specification. 137 Specify rfc3164 to perform logging in RFC-3164 compatible format. Specify rfc5424 to perform 138 logging in RFC-5424 compatible format 139 140 141 ## journald options 142 143 The `journald` logging driver stores the container id in the journal's `CONTAINER_ID` field. For detailed information on 144 working with this logging driver, see [the journald logging driver](journald.md) 145 reference documentation. 146 147 ## gelf options 148 149 The GELF logging driver supports the following options: 150 151 --log-opt gelf-address=udp://host:port 152 --log-opt tag="database" 153 --log-opt labels=label1,label2 154 --log-opt env=env1,env2 155 --log-opt gelf-compression-type=gzip 156 --log-opt gelf-compression-level=1 157 158 The `gelf-address` option specifies the remote GELF server address that the 159 driver connects to. Currently, only `udp` is supported as the transport and you must 160 specify a `port` value. The following example shows how to connect the `gelf` 161 driver to a GELF remote server at `192.168.0.42` on port `12201` 162 163 $ docker run --log-driver=gelf --log-opt gelf-address=udp://192.168.0.42:12201 164 165 By default, Docker uses the first 12 characters of the container ID to tag log messages. 166 Refer to the [log tag option documentation](log_tags.md) for customizing 167 the log tag format. 168 169 The `labels` and `env` options are supported by the gelf logging 170 driver. It adds additional key on the `extra` fields, prefixed by an 171 underscore (`_`). 172 173 // […] 174 "_foo": "bar", 175 "_fizz": "buzz", 176 // […] 177 178 The `gelf-compression-type` option can be used to change how the GELF driver 179 compresses each log message. The accepted values are `gzip`, `zlib` and `none`. 180 `gzip` is chosen by default. 181 182 The `gelf-compression-level` option can be used to change the level of compresssion 183 when `gzip` or `zlib` is selected as `gelf-compression-type`. Accepted value 184 must be from from -1 to 9 (BestCompression). Higher levels typically 185 run slower but compress more. Default value is 1 (BestSpeed). 186 187 ## fluentd options 188 189 You can use the `--log-opt NAME=VALUE` flag to specify these additional Fluentd logging driver options. 190 191 - `fluentd-address`: specify `host:port` to connect [localhost:24224] 192 - `tag`: specify tag for `fluentd` message 193 - `fluentd-buffer-limit`: specify the maximum size of the fluentd log buffer [8MB] 194 - `fluentd-retry-wait`: initial delay before a connection retry (after which it increases exponentially) [1000ms] 195 - `fluentd-max-retries`: maximum number of connection retries before abrupt failure of docker [1073741824] 196 - `fluentd-async-connect`: whether to block on initial connection or not [false] 197 198 For example, to specify both additional options: 199 200 `docker run --log-driver=fluentd --log-opt fluentd-address=localhost:24224 --log-opt tag=docker.{{.Name}}` 201 202 If container cannot connect to the Fluentd daemon on the specified address and 203 `fluentd-async-connect` is not enabled, the container stops immediately. 204 For detailed information on working with this logging driver, 205 see [the fluentd logging driver](fluentd.md) 206 207 208 ## Specify Amazon CloudWatch Logs options 209 210 The Amazon CloudWatch Logs logging driver supports the following options: 211 212 --log-opt awslogs-region=<aws_region> 213 --log-opt awslogs-group=<log_group_name> 214 --log-opt awslogs-stream=<log_stream_name> 215 216 217 For detailed information on working with this logging driver, see [the awslogs logging driver](awslogs.md) reference documentation. 218 219 ## Splunk options 220 221 The Splunk logging driver requires the following options: 222 223 --log-opt splunk-token=<splunk_http_event_collector_token> 224 --log-opt splunk-url=https://your_splunk_instance:8088 225 226 For detailed information about working with this logging driver, see the [Splunk logging driver](splunk.md) 227 reference documentation. 228 229 ## ETW logging driver options 230 231 The etwlogs logging driver does not require any options to be specified. This logging driver will forward each log message 232 as an ETW event. An ETW listener can then be created to listen for these events. 233 234 For detailed information on working with this logging driver, see [the ETW logging driver](etwlogs.md) reference documentation. 235 236 ## Google Cloud Logging 237 238 The Google Cloud Logging driver supports the following options: 239 240 --log-opt gcp-project=<gcp_projext> 241 --log-opt labels=<label1>,<label2> 242 --log-opt env=<envvar1>,<envvar2> 243 --log-opt log-cmd=true 244 245 For detailed information about working with this logging driver, see the [Google Cloud Logging driver](gcplogs.md). 246 reference documentation.