github.com/walkingsparrow/docker@v1.4.2-0.20151218153551-b708a2249bfa/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 | `splunk` | Splunk logging driver for Docker. Writes log messages to `splunk` using HTTP Event Collector. | 28 29 The `docker logs`command is available only for the `json-file` and `journald` 30 logging drivers. 31 32 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. 33 34 To use attributes, specify them when you start the Docker daemon. 35 36 ``` 37 docker daemon --log-driver=json-file --log-opt labels=foo --log-opt env=foo,fizz 38 ``` 39 40 Then, run a container and specify values for the `labels` or `env`. For example, you might use this: 41 42 ``` 43 docker run --label foo=bar -e fizz=buzz -d -P training/webapp python app.py 44 ``` 45 46 This adds additional fields to the log depending on the driver, e.g. for 47 `json-file` that looks like: 48 49 "attrs":{"fizz":"buzz","foo":"bar"} 50 51 52 ## json-file options 53 54 The following logging options are supported for the `json-file` logging driver: 55 56 --log-opt max-size=[0-9+][k|m|g] 57 --log-opt max-file=[0-9+] 58 --log-opt labels=label1,label2 59 --log-opt env=env1,env2 60 61 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. 62 63 `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. 64 65 If `max-size` and `max-file` are set, `docker logs` only returns the log lines from the newest log file. 66 67 68 ## syslog options 69 70 The following logging options are supported for the `syslog` logging driver: 71 72 --log-opt syslog-address=[tcp|udp]://host:port 73 --log-opt syslog-address=unix://path 74 --log-opt syslog-facility=daemon 75 --log-opt tag="mailer" 76 77 `syslog-address` specifies the remote syslog server address where the driver connects to. 78 If not specified it defaults to the local unix socket of the running system. 79 If transport is either `tcp` or `udp` and `port` is not specified it defaults to `514` 80 The following example shows how to have the `syslog` driver connect to a `syslog` 81 remote server at `192.168.0.42` on port `123` 82 83 $ docker run --log-driver=syslog --log-opt syslog-address=tcp://192.168.0.42:123 84 85 The `syslog-facility` option configures the syslog facility. By default, the system uses the 86 `daemon` value. To override this behavior, you can provide an integer of 0 to 23 or any of 87 the following named facilities: 88 89 * `kern` 90 * `user` 91 * `mail` 92 * `daemon` 93 * `auth` 94 * `syslog` 95 * `lpr` 96 * `news` 97 * `uucp` 98 * `cron` 99 * `authpriv` 100 * `ftp` 101 * `local0` 102 * `local1` 103 * `local2` 104 * `local3` 105 * `local4` 106 * `local5` 107 * `local6` 108 * `local7` 109 110 By default, Docker uses the first 12 characters of the container ID to tag log messages. 111 Refer to the [log tag option documentation](log_tags.md) for customizing 112 the log tag format. 113 114 115 ## journald options 116 117 The `journald` logging driver stores the container id in the journal's `CONTAINER_ID` field. For detailed information on 118 working with this logging driver, see [the journald logging driver](journald.md) 119 reference documentation. 120 121 ## gelf options 122 123 The GELF logging driver supports the following options: 124 125 --log-opt gelf-address=udp://host:port 126 --log-opt tag="database" 127 --log-opt labels=label1,label2 128 --log-opt env=env1,env2 129 130 The `gelf-address` option specifies the remote GELF server address that the 131 driver connects to. Currently, only `udp` is supported as the transport and you must 132 specify a `port` value. The following example shows how to connect the `gelf` 133 driver to a GELF remote server at `192.168.0.42` on port `12201` 134 135 $ docker run --log-driver=gelf --log-opt gelf-address=udp://192.168.0.42:12201 136 137 By default, Docker uses the first 12 characters of the container ID to tag log messages. 138 Refer to the [log tag option documentation](log_tags.md) for customizing 139 the log tag format. 140 141 The `labels` and `env` options are supported by the gelf logging 142 driver. It adds additional key on the `extra` fields, prefixed by an 143 underscore (`_`). 144 145 // […] 146 "_foo": "bar", 147 "_fizz": "buzz", 148 // […] 149 150 151 ## fluentd options 152 153 You can use the `--log-opt NAME=VALUE` flag to specify these additional Fluentd logging driver options. 154 155 - `fluentd-address`: specify `host:port` to connect [localhost:24224] 156 - `tag`: specify tag for `fluentd` message, 157 158 For example, to specify both additional options: 159 160 `docker run --log-driver=fluentd --log-opt fluentd-address=localhost:24224 --log-opt tag=docker.{{.Name}}` 161 162 If container cannot connect to the Fluentd daemon on the specified address, 163 the container stops immediately. For detailed information on working with this 164 logging driver, see [the fluentd logging driver](fluentd.md) 165 166 167 ## Specify Amazon CloudWatch Logs options 168 169 The Amazon CloudWatch Logs logging driver supports the following options: 170 171 --log-opt awslogs-region=<aws_region> 172 --log-opt awslogs-group=<log_group_name> 173 --log-opt awslogs-stream=<log_stream_name> 174 175 176 For detailed information on working with this logging driver, see [the awslogs logging driver](awslogs.md) reference documentation. 177 178 ## Splunk options 179 180 The Splunk logging driver requires the following options: 181 182 --log-opt splunk-token=<splunk_http_event_collector_token> 183 --log-opt splunk-url=https://your_splunk_instance:8088 184 185 For detailed information about working with this logging driver, see the [Splunk logging driver](splunk.md) 186 reference documentation.