github.com/sijibomii/docker@v0.0.0-20231230191044-5cf6ca554647/docs/admin/logging/gcplogs.md (about) 1 <!--[metadata]> 2 +++ 3 title = "Google Cloud Logging driver" 4 description = "Describes how to use the Google Cloud Logging driver." 5 keywords = ["gcplogs, google, docker, logging, driver"] 6 [menu.main] 7 parent = "smn_logging" 8 weight = 2 9 +++ 10 <![end-metadata]--> 11 12 # Google Cloud Logging driver 13 14 The Google Cloud Logging driver sends container logs to <a href="https://cloud.google.com/logging/docs/" target="_blank">Google Cloud 15 Logging</a>. 16 17 ## Usage 18 19 You can configure the default logging driver by passing the `--log-driver` 20 option to the Docker daemon: 21 22 docker daemon --log-driver=gcplogs 23 24 You can set the logging driver for a specific container by using the 25 `--log-driver` option to `docker run`: 26 27 docker run --log-driver=gcplogs ... 28 29 This log driver does not implement a reader so it is incompatible with 30 `docker logs`. 31 32 If Docker detects that it is running in a Google Cloud Project, it will discover configuration 33 from the <a href="https://cloud.google.com/compute/docs/metadata" target="_blank">instance metadata service</a>. 34 Otherwise, the user must specify which project to log to using the `--gcp-project` 35 log option and Docker will attempt to obtain credentials from the 36 <a href="https://developers.google.com/identity/protocols/application-default-credentials" target="_blank">Google Application Default Credential</a>. 37 The `--gcp-project` takes precedence over information discovered from the metadata server 38 so a Docker daemon running in a Google Cloud Project can be overriden to log to a different 39 Google Cloud Project using `--gcp-project`. 40 41 ## gcplogs options 42 43 You can use the `--log-opt NAME=VALUE` flag to specify these additional Google 44 Cloud Logging driver options: 45 46 | Option | Required | Description | 47 |-----------------------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------| 48 | `gcp-project` | optional | Which GCP project to log to. Defaults to discovering this value from the GCE metadata service. | 49 | `gcp-log-cmd` | optional | Whether to log the command that the container was started with. Defaults to false. | 50 | `labels` | optional | Comma-separated list of keys of labels, which should be included in message, if these labels are specified for container. | 51 | `env` | optional | Comma-separated list of keys of environment variables, which should be included in message, if these variables are specified for container. | 52 53 If there is collision between `label` and `env` keys, the value of the `env` 54 takes precedence. Both options add additional fields to the attributes of a 55 logging message. 56 57 Below is an example of the logging options required to log to the default 58 logging destination which is discovered by querying the GCE metadata server. 59 60 docker run --log-driver=gcplogs \ 61 --log-opt labels=location 62 --log-opt env=TEST 63 --log-opt gcp-log-cmd=true 64 --env "TEST=false" 65 --label location=west 66 your/application 67 68 This configuration also directs the driver to include in the payload the label 69 `location`, the environment variable `ENV`, and the command used to start the 70 container.