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

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