Logging and viewing logs

This page describes the logs available when using Cloud Run, and how to view and write logs.

Cloud Run has two types of logs, and these are automatically sent to Cloud Logging:

  • Request logs: logs of requests sent to Cloud Run services. These logs are created automatically.
  • Container logs: logs emitted from the container instances, typically from your own code, written to supported locations as described in Writing container logs.

Viewing logs

You can view logs for your service in a couple of ways:

  • Use the Cloud Run page in the Cloud Console
  • Use Cloud Logging Logs Viewer in the Cloud Console.

Both of these viewing methods examine the same logs stored in Cloud Logging, but the Cloud Logging Logs Viewer provides more details and more filtering capabilities.

Viewing logs in Cloud Run

To view logs in the Cloud Run page:

  1. Go to Cloud Run

  2. Click the desired service in the displayed list.

  3. Click the LOGS tab to get the request and container logs for all revisions of this service. You can filter by log severity level.

Viewing logs in Cloud Logging

To view your Cloud Run logs in the Cloud Logging Logs Viewer:

  1. Go to the Logs Viewer page in the Cloud Console:

    Go to the Logs Viewer page

  2. Select an existing Google Cloud project at the top of the page, or create a new project.

  3. Using the drop-down menus, select the resource: Kubernetes Container.

For more information, read Viewing logs on Google Cloud's operations suite Logging.

Viewing logs in Cloud Code

To view your logs in Cloud Code, read the IntelliJ and Visual Studio Code guides.

Reading logs programmatically

If you want to read the logs programmatically, you can use one of these methods:

Writing container logs

When you write logs from your service, they will be picked up automatically by Cloud Logging so long as the logs are written to any of these locations:

Most developers are expected to write logs using standard output and standard error.

The container logs written to these supported locations are automatically associated with the Cloud Run service, revision, and location.

Correlating your container logs with a request log

In the Logs Viewer, logs correlated by the same trace are viewable in "parent-child" format: when you click on the triangle icon at the left of the request log entry, the container logs related to that request show up nested under the request log.

Container logs are not automatically correlated to request logs unless you use a Cloud Logging client library. To correlate container logs with request logs without using a client library, you can use a structured JSON log line that contains a logging.googleapis.com/trace field with the trace identifier extracted from the X-Cloud-Trace-Context header as shown in the above sample for structured logging.

Controlling request log resource usage

Request logs are created automatically. Although you cannot control the amount of request logs directly from Cloud Run, you can make use of the logs exclusion feature from Cloud Logging.

A note about logging agents

If you've used Cloud Logging with certain Google Cloud products, such as Compute Engine, you may have used Cloud Logging logging agents. Cloud Run does not use logging agents because it has built-in support for log collection.

Logging resource

Clicking on a log entry in the Logs Viewer opens up a JSON formatted log entry so you can drill down to the details you want.

All of the fields in a log entry, such as timestamps, severity, and httpRequest are standard, and are described in the documentation for a log entry.

However, there are some labels or resource labels that are special to Cloud Run. These are listed here with sample contents:

 httpRequest: {…}
 insertId:  "5c82b3d1000ece0000000000"
 labels: {
  instanceId:  "00bf4bf00000fb59c906a00000c9e29c2c4e06dce91500000000056008d2b6460f163c0057b97b2345f2725fb2423ee5f0bafd36df887fdb1122371563cf1ff453717282afe000001"
 logName:  "projects/my-project/logs/kuberun/.googleapis.com%2Frequests"
 receiveTimestamp:  "2019-03-08T18:26:25.981686167Z"
 resource: {
  labels: {
   configuration_name:  "myservice"
   location:  "us-central1"
   project_id:  "my-project"
   revision_name:  "myservice-00002"
   service_name:  "myservice"
  type:  "cloud_run_revision"
 severity:  "INFO"
 timestamp:  "2019-03-08T18:26:25.970397Z"
Field Values and notes
instanceId The container instance that handled the request.
logName Identifies the log, for example, request log, standard error, standard output, etc.
configuration_name The Configuration resource that created the revision that served the request.
location Identifies the GCP location of the service.
project_id The project the service is deployed to.
revision_name The revision that served the request.
service_name The service that served the request.
type cloud_run_revision. The Cloud Run resource type.