github.com/slene/docker@v1.8.0-rc1/docs/reference/logging/journald.md (about) 1 <!--[metadata]> 2 +++ 3 title = "journald logging driver" 4 description = "Describes how to use the fluentd logging driver." 5 keywords = ["Fluentd, docker, logging, driver"] 6 [menu.main] 7 parent = "smn_logging" 8 +++ 9 <![end-metadata]--> 10 11 # Journald logging driver 12 13 The `journald` logging driver sends container logs to the [systemd 14 journal](http://www.freedesktop.org/software/systemd/man/systemd-journald.service.html). Log entries can be retrieved using the `journalctl` 15 command or through use of the journal API. 16 17 In addition to the text of the log message itself, the `journald` log 18 driver stores the following metadata in the journal with each message: 19 20 | Field | Description | 21 ----------------------|-------------| 22 | `CONTAINER_ID` | The container ID truncated to 12 characters. | 23 | `CONTAINER_ID_FULL` | The full 64-character container ID. | 24 | `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. | 25 26 ## Usage 27 28 You can configure the default logging driver by passing the 29 `--log-driver` option to the Docker daemon: 30 31 docker --log-driver=journald 32 33 You can set the logging driver for a specific container by using the 34 `--log-driver` option to `docker run`: 35 36 docker run --log-driver=journald ... 37 38 ## Note regarding container names 39 40 The value logged in the `CONTAINER_NAME` field is the container name 41 that was set at startup. If you use `docker rename` to rename a 42 container, the new name will not be reflected in the journal entries. 43 Journal entries will continue to use the original name. 44 45 ## Retrieving log messages with journalctl 46 47 You can use the `journalctl` command to retrieve log messages. You 48 can apply filter expressions to limit the retrieved messages to a 49 specific container. For example, to retrieve all log messages from a 50 container referenced by name: 51 52 # journalctl CONTAINER_NAME=webserver 53 54 You can make use of additional filters to further limit the messages 55 retrieved. For example, to see just those messages generated since 56 the system last booted: 57 58 # journalctl -b CONTAINER_NAME=webserver 59 60 Or to retrieve log messages in JSON format with complete metadata: 61 62 # journalctl -o json CONTAINER_NAME=webserver 63 64 ## Retrieving log messages with the journal API 65 66 This example uses the `systemd` Python module to retrieve container 67 logs: 68 69 import systemd.journal 70 71 reader = systemd.journal.Reader() 72 reader.add_match('CONTAINER_NAME=web') 73 74 for msg in reader: 75 print '{CONTAINER_ID_FULL}: {MESSAGE}'.format(**msg) 76