2015-06-25 08:00:49 -04:00
<!-- [metadata]>
+++
title = "Fluentd logging driver"
description = "Describes how to use the fluentd logging driver."
keywords = ["Fluentd, docker, logging, driver"]
[menu.main]
parent = "smn_logging"
2015-08-06 18:50:44 -04:00
weight=2
2015-06-25 08:00:49 -04:00
+++
<![end-metadata]-->
# Fluentd logging driver
The `fluentd` logging driver sends container logs to the
[Fluentd ](http://www.fluentd.org/ ) collector as structured log data. Then, users
can use any of the [various output plugins of
Fluentd](http://www.fluentd.org/plugins) to write these logs to various
destinations.
In addition to the log message itself, the `fluentd` log
driver sends the following metadata in the structured log message:
| Field | Description |
-------------------|-------------------------------------|
| `container_id` | The full 64-character container ID. |
| `container_name` | The container name at the time it was started. If you use `docker rename` to rename a container, the new name is not reflected in the journal entries. |
| `source` | `stdout` or `stderr` |
2015-07-28 17:02:57 -04:00
The `docker logs` command is not available for this logging driver.
2015-06-25 08:00:49 -04:00
## Usage
2015-07-28 17:02:57 -04:00
Some options are supported by specifying `--log-opt` as many times as needed:
- `fluentd-address` : specify `host:port` to connect `localhost:24224`
2015-08-06 18:50:44 -04:00
- `tag` : specify tag for fluentd message, which interpret some markup, ex `{{.ID}}` , `{{.FullID}}` or `{{.Name}}` `docker.{{.ID}}`
2015-07-28 17:02:57 -04:00
2015-06-25 08:00:49 -04:00
Configure the default logging driver by passing the
`--log-driver` option to the Docker daemon:
2015-10-27 03:50:23 -04:00
docker daemon --log-driver=fluentd
2015-06-25 08:00:49 -04:00
To set the logging driver for a specific container, pass the
`--log-driver` option to `docker run` :
docker run --log-driver=fluentd ...
Before using this logging driver, launch a Fluentd daemon. The logging driver
connects to this daemon through `localhost:24224` by default. Use the
`fluentd-address` option to connect to a different address.
docker run --log-driver=fluentd --log-opt fluentd-address=myhost.local:24224
If container cannot connect to the Fluentd daemon, the container stops
immediately.
## Options
Users can use the `--log-opt NAME=VALUE` flag to specify additional Fluentd logging driver options.
### fluentd-address
By default, the logging driver connects to `localhost:24224` . Supply the
`fluentd-address` option to connect to a different address.
docker run --log-driver=fluentd --log-opt fluentd-address=myhost.local:24224
2015-08-06 18:50:44 -04:00
### tag
2015-06-25 08:00:49 -04:00
2015-08-06 18:50:44 -04:00
By default, Docker uses the first 12 characters of the container ID to tag log messages.
2015-10-09 19:50:41 -04:00
Refer to the [log tag option documentation ](log_tags.md ) for customizing
2015-08-06 18:50:44 -04:00
the log tag format.
2015-06-25 08:00:49 -04:00
2015-10-13 02:39:47 -04:00
### labels and env
2015-10-13 12:44:17 -04:00
The `labels` and `env` options each take a comma-separated list of keys. If there is collision between `label` and `env` keys, the value of the `env` takes precedence. Both options add additional fields to the extra attributes of a logging message.
2015-10-13 02:39:47 -04:00
2015-06-25 08:00:49 -04:00
## Fluentd daemon management with Docker
About `Fluentd` itself, see [the project webpage ](http://www.fluentd.org )
and [its documents ](http://docs.fluentd.org/ ).
To use this logging driver, start the `fluentd` daemon on a host. We recommend
that you use [the Fluentd docker
image](https://registry.hub.docker.com/u/fluent/fluentd/). This image is
especially useful if you want to aggregate multiple container logs on a each
host then, later, transfer the logs to another Fluentd node to create an
aggregate store.
### Testing container loggers
1. Write a configuration file (`test.conf`) to dump input logs:
< source >
@type forward
< / source >
2015-10-13 12:44:17 -04:00
2015-06-25 08:00:49 -04:00
< match docker . * * >
@type stdout
< / match >
2. Launch Fluentd container with this configuration file:
$ docker run -it -p 24224:24224 -v /path/to/conf/test.conf:/fluentd/etc -e FLUENTD_CONF=test.conf fluent/fluentd:latest
3. Start one or more containers with the `fluentd` logging driver:
$ docker run --log-driver=fluentd your/application