github.com/sijibomii/docker@v0.0.0-20231230191044-5cf6ca554647/docs/admin/logging/overview.md (about)

     1  <!--[metadata]>
     2  +++
     3  aliases = ["/engine/reference/logging/overview/"]
     4  title = "Configuring Logging Drivers"
     5  description = "Configure logging driver."
     6  keywords = ["docker, logging, driver, Fluentd"]
     7  [menu.main]
     8  parent = "smn_logging"
     9  weight=-1
    10  +++
    11  <![end-metadata]-->
    12  
    13  
    14  # Configure logging drivers
    15  
    16  The container can have a different logging driver than the Docker daemon. Use
    17  the `--log-driver=VALUE` with the `docker run` command to configure the
    18  container's logging driver. The following options are supported:
    19  
    20  | `none`      | Disables any logging for the container. `docker logs` won't be available with this driver.                                    |
    21  |-------------|-------------------------------------------------------------------------------------------------------------------------------|
    22  | `json-file` | Default logging driver for Docker. Writes JSON messages to file.                                                              |
    23  | `syslog`    | Syslog logging driver for Docker. Writes log messages to syslog.                                                              |
    24  | `journald`  | Journald logging driver for Docker. Writes log messages to `journald`.                                                        |
    25  | `gelf`      | Graylog Extended Log Format (GELF) logging driver for Docker. Writes log messages to a GELF endpoint likeGraylog or Logstash. |
    26  | `fluentd`   | Fluentd logging driver for Docker. Writes log messages to `fluentd` (forward input).                                          |
    27  | `awslogs`   | Amazon CloudWatch Logs logging driver for Docker. Writes log messages to Amazon CloudWatch Logs.                              |
    28  | `splunk`    | Splunk logging driver for Docker. Writes log messages to `splunk` using HTTP Event Collector.                                 |
    29  | `etwlogs`   | ETW logging driver for Docker on Windows. Writes log messages as ETW events.                                                  |
    30  | `gcplogs`   | Google Cloud Logging driver for Docker. Writes log messages to Google Cloud Logging.                                          |
    31  
    32  The `docker logs`command is available only for the `json-file` and `journald`
    33  logging drivers.
    34  
    35  The `labels` and `env` options add additional attributes for use with logging drivers that accept them. Each option takes a comma-separated list of keys. If there is collision between `label` and `env` keys, the value of the `env` takes precedence.
    36  
    37  To use attributes, specify them when you start the Docker daemon.
    38  
    39  ```
    40  docker daemon --log-driver=json-file --log-opt labels=foo --log-opt env=foo,fizz
    41  ```
    42  
    43  Then, run a container and specify values for the `labels` or `env`.  For example, you might use this:
    44  
    45  ```
    46  docker run --label foo=bar -e fizz=buzz -d -P training/webapp python app.py
    47  ```
    48  
    49  This adds additional fields to the log depending on the driver, e.g. for
    50  `json-file` that looks like:
    51  
    52      "attrs":{"fizz":"buzz","foo":"bar"}
    53  
    54  
    55  ## json-file options
    56  
    57  The following logging options are supported for the `json-file` logging driver:
    58  
    59      --log-opt max-size=[0-9+][k|m|g]
    60      --log-opt max-file=[0-9+]
    61      --log-opt labels=label1,label2
    62      --log-opt env=env1,env2
    63  
    64  Logs that reach `max-size` are rolled over. You can set the size in kilobytes(k), megabytes(m), or gigabytes(g). eg `--log-opt max-size=50m`. If `max-size` is not set, then logs are not rolled over.
    65  
    66  `max-file` specifies the maximum number of files that a log is rolled over before being discarded. eg `--log-opt max-file=100`. If `max-size` is not set, then `max-file` is not honored.
    67  
    68  If `max-size` and `max-file` are set, `docker logs` only returns the log lines from the newest log file.
    69  
    70  
    71  ## syslog options
    72  
    73  The following logging options are supported for the `syslog` logging driver:
    74  
    75      --log-opt syslog-address=[tcp|udp|tcp+tls]://host:port
    76      --log-opt syslog-address=unix://path
    77      --log-opt syslog-facility=daemon
    78      --log-opt syslog-tls-ca-cert=/etc/ca-certificates/custom/ca.pem
    79      --log-opt syslog-tls-cert=/etc/ca-certificates/custom/cert.pem
    80      --log-opt syslog-tls-key=/etc/ca-certificates/custom/key.pem
    81      --log-opt syslog-tls-skip-verify=true
    82      --log-opt tag="mailer"
    83      --log-opt syslog-format=[rfc5424|rfc5424micro|rfc3164]
    84      --log-opt env=ENV1,ENV2,ENV3
    85      --log-opt labels=label1,label2,label3
    86  
    87  `syslog-address` specifies the remote syslog server address where the driver connects to.
    88  If not specified it defaults to the local unix socket of the running system.
    89  If transport is either `tcp` or `udp` and `port` is not specified it defaults to `514`
    90  The following example shows how to have the `syslog` driver connect to a `syslog`
    91  remote server at `192.168.0.42` on port `123`
    92  
    93      $ docker run --log-driver=syslog --log-opt syslog-address=tcp://192.168.0.42:123
    94  
    95  The `syslog-facility` option configures the syslog facility. By default, the system uses the
    96  `daemon` value. To override this behavior, you can provide an integer of 0 to 23 or any of
    97  the following named facilities:
    98  
    99  * `kern`
   100  * `user`
   101  * `mail`
   102  * `daemon`
   103  * `auth`
   104  * `syslog`
   105  * `lpr`
   106  * `news`
   107  * `uucp`
   108  * `cron`
   109  * `authpriv`
   110  * `ftp`
   111  * `local0`
   112  * `local1`
   113  * `local2`
   114  * `local3`
   115  * `local4`
   116  * `local5`
   117  * `local6`
   118  * `local7`
   119  
   120  `syslog-tls-ca-cert` specifies the absolute path to the trust certificates
   121  signed by the CA. This option is ignored if the address protocol is not `tcp+tls`.
   122  
   123  `syslog-tls-cert` specifies the absolute path to the TLS certificate file.
   124  This option is ignored if the address protocol is not `tcp+tls`.
   125  
   126  `syslog-tls-key` specifies the absolute path to the TLS key file.
   127  This option is ignored if the address protocol is not `tcp+tls`.
   128  
   129  `syslog-tls-skip-verify` configures the TLS verification.
   130  This verification is enabled by default, but it can be overriden by setting
   131  this option to `true`. This option is ignored if the address protocol is not `tcp+tls`.
   132  
   133  `tag` configures a string that is appended to the APP-NAME in the syslog message.
   134  By default, Docker uses the first 12 characters of the container ID to tag log messages.
   135  Refer to the [log tag option documentation](log_tags.md) for customizing
   136  the log tag format.
   137  
   138  `syslog-format` specifies syslog message format to use when logging.
   139  If not specified it defaults to the local unix syslog format without hostname specification.
   140  Specify rfc3164 to perform logging in RFC-3164 compatible format. Specify rfc5424 to perform 
   141  logging in RFC-5424 compatible format. Specify rfc5424micro to perform logging in RFC-5424
   142  compatible format with microsecond timestamp resolution.
   143  
   144  `env` should be a comma-separated list of keys of environment variables. Used for
   145  advanced [log tag options](log_tags.md).
   146  
   147  `labels` should be a comma-separated list of keys of labels. Used for advanced
   148  [log tag options](log_tags.md).
   149  
   150  ## journald options
   151  
   152  The `journald` logging driver stores the container id in the journal's `CONTAINER_ID` field. For detailed information on
   153  working with this logging driver, see [the journald logging driver](journald.md)
   154  reference documentation.
   155  
   156  ## gelf options
   157  
   158  The GELF logging driver supports the following options:
   159  
   160      --log-opt gelf-address=udp://host:port
   161      --log-opt tag="database"
   162      --log-opt labels=label1,label2
   163      --log-opt env=env1,env2
   164      --log-opt gelf-compression-type=gzip
   165      --log-opt gelf-compression-level=1
   166  
   167  The `gelf-address` option specifies the remote GELF server address that the
   168  driver connects to. Currently, only `udp` is supported as the transport and you must
   169  specify a `port` value. The following example shows how to connect the `gelf`
   170  driver to a GELF remote server at `192.168.0.42` on port `12201`
   171  
   172      $ docker run --log-driver=gelf --log-opt gelf-address=udp://192.168.0.42:12201
   173  
   174  By default, Docker uses the first 12 characters of the container ID to tag log messages.
   175  Refer to the [log tag option documentation](log_tags.md) for customizing
   176  the log tag format.
   177  
   178  The `labels` and `env` options are supported by the gelf logging
   179  driver. It adds additional key on the `extra` fields, prefixed by an
   180  underscore (`_`).
   181  
   182      // […]
   183      "_foo": "bar",
   184      "_fizz": "buzz",
   185      // […]
   186  
   187  The `gelf-compression-type` option can be used to change how the GELF driver
   188  compresses each log message. The accepted values are `gzip`, `zlib` and `none`.
   189  `gzip` is chosen by default.
   190  
   191  The `gelf-compression-level` option can be used to change the level of compresssion
   192  when `gzip` or `zlib` is selected as `gelf-compression-type`. Accepted value
   193  must be from from -1 to 9 (BestCompression). Higher levels typically
   194  run slower but compress more. Default value is 1 (BestSpeed).
   195  
   196  ## fluentd options
   197  
   198  You can use the `--log-opt NAME=VALUE` flag to specify these additional Fluentd logging driver options.
   199  
   200   - `fluentd-address`: specify `host:port` to connect [localhost:24224]
   201   - `tag`: specify tag for `fluentd` message
   202   - `fluentd-buffer-limit`: specify the maximum size of the fluentd log buffer [8MB]
   203   - `fluentd-retry-wait`: initial delay before a connection retry (after which it increases exponentially) [1000ms]
   204   - `fluentd-max-retries`: maximum number of connection retries before abrupt failure of docker [1073741824]
   205   - `fluentd-async-connect`: whether to block on initial connection or not [false]
   206  
   207  For example, to specify both additional options:
   208  
   209  `docker run --log-driver=fluentd --log-opt fluentd-address=localhost:24224 --log-opt tag=docker.{{.Name}}`
   210  
   211  If container cannot connect to the Fluentd daemon on the specified address and
   212  `fluentd-async-connect` is not enabled, the container stops immediately.
   213  For detailed information on working with this logging driver,
   214  see [the fluentd logging driver](fluentd.md)
   215  
   216  
   217  ## Specify Amazon CloudWatch Logs options
   218  
   219  The Amazon CloudWatch Logs logging driver supports the following options:
   220  
   221      --log-opt awslogs-region=<aws_region>
   222      --log-opt awslogs-group=<log_group_name>
   223      --log-opt awslogs-stream=<log_stream_name>
   224  
   225  
   226  For detailed information on working with this logging driver, see [the awslogs logging driver](awslogs.md) reference documentation.
   227  
   228  ## Splunk options
   229  
   230  The Splunk logging driver requires the following options:
   231  
   232      --log-opt splunk-token=<splunk_http_event_collector_token>
   233      --log-opt splunk-url=https://your_splunk_instance:8088
   234  
   235  For detailed information about working with this logging driver, see the [Splunk logging driver](splunk.md)
   236  reference documentation.
   237  
   238  ## ETW logging driver options
   239  
   240  The etwlogs logging driver does not require any options to be specified. This logging driver will forward each log message
   241  as an ETW event. An ETW listener can then be created to listen for these events. 
   242  
   243  For detailed information on working with this logging driver, see [the ETW logging driver](etwlogs.md) reference documentation.
   244  
   245  ## Google Cloud Logging
   246  
   247  The Google Cloud Logging driver supports the following options:
   248  
   249      --log-opt gcp-project=<gcp_projext>
   250      --log-opt labels=<label1>,<label2>
   251      --log-opt env=<envvar1>,<envvar2>
   252      --log-opt log-cmd=true
   253  
   254  For detailed information about working with this logging driver, see the [Google Cloud Logging driver](gcplogs.md).
   255  reference documentation.