github.com/portworx/docker@v1.12.1/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 = ["Journald, docker, logging, driver"]
     7  [menu.main]
     8  parent = "smn_logging"
     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  | `CONTAINER_TAG`     | The container tag ([log tag option documentation](log_tags.md)). |
    27  
    28  ## Usage
    29  
    30  You can configure the default logging driver by passing the
    31  `--log-driver` option to the Docker daemon:
    32  
    33      docker daemon --log-driver=journald
    34  
    35  You can set the logging driver for a specific container by using the
    36  `--log-driver` option to `docker run`:
    37  
    38      docker run --log-driver=journald ...
    39  
    40  ## Options
    41  
    42  Users can use the `--log-opt NAME=VALUE` flag to specify additional
    43  journald logging driver options.
    44  
    45  ### tag
    46  
    47  Specify template to set `CONTAINER_TAG` value in journald logs. Refer to
    48  [log tag option documentation](log_tags.md) for customizing the log tag format.
    49  
    50  ### labels and env
    51  
    52  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.
    53  
    54  ## Note regarding container names
    55  
    56  The value logged in the `CONTAINER_NAME` field is the container name
    57  that was set at startup.  If you use `docker rename` to rename a
    58  container, the new name will not be reflected in the journal entries.
    59  Journal entries will continue to use the original name.
    60  
    61  ## Retrieving log messages with journalctl
    62  
    63  You can use the `journalctl` command to retrieve log messages.  You
    64  can apply filter expressions to limit the retrieved messages to a
    65  specific container.  For example, to retrieve all log messages from a
    66  container referenced by name:
    67  
    68      # journalctl CONTAINER_NAME=webserver
    69  
    70  You can make use of additional filters to further limit the messages
    71  retrieved.  For example, to see just those messages generated since
    72  the system last booted:
    73  
    74      # journalctl -b CONTAINER_NAME=webserver
    75  
    76  Or to retrieve log messages in JSON format with complete metadata:
    77  
    78      # journalctl -o json CONTAINER_NAME=webserver
    79  
    80  ## Retrieving log messages with the journal API
    81  
    82  This example uses the `systemd` Python module to retrieve container
    83  logs:
    84  
    85      import systemd.journal
    86  
    87      reader = systemd.journal.Reader()
    88      reader.add_match('CONTAINER_NAME=web')
    89  
    90      for msg in reader:
    91        print '{CONTAINER_ID_FULL}: {MESSAGE}'.format(**msg)