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