Quickstart

This page shows you how to read and write log entries in Stackdriver Logging.

Before you begin

  1. Sign in to your Google account.

    If you don't already have one, sign up for a new account.

  2. Select or create a Cloud Platform project.

    Go to the Manage resources page

  3. Enable billing for your project.

    Enable billing

  4. Install and initialize the Cloud SDK.
  5. Install the gcloud beta commands component:
    gcloud components install beta

Write log entries using the Cloud SDK

  1. Use the following gcloud command to write a simple text log entry directly to Stackdriver Logging:

    gcloud beta logging write my-test-log "A simple entry"
    
  2. Use gcloud again to write a structured log entry to Stackdriver Logging:

    gcloud beta logging write --payload-type=json my-test-log '{ "message": "My second entry", "weather": "partly cloudy"}'
    

View logs in the Logs Viewer

  1. Go to the Logs Viewer page in the Google Cloud Platform Console.

    Go to the Logs Viewer page

  2. You see the Logs Viewer page:

    Logs Viewer

    Make sure your project is selected in the top navigation bar.

    This page allows you to view and filter all your logs. If your project uses Google Cloud Platform services, you might also see log entries from those services.

  3. In the drop-down menu above the log entries, choose Global to see the log entries you wrote with gcloud.

    Logs Viewer Global

    If you don't see the Global menu option or if you don't see your log entries, wait a few minutes for your log entries to be received by Stackdriver Logging, and then refresh the Stackdriver Logging page.

  4. Expand the two log entries by clicking the disclosure icons to the left of the log entries. You see the fields inside each log entry:

    Logs Viewer

    A simple entry, has its text stored in the field textPayload. My second entry, is a structured log entry contained in the field jsonPayload. The structured payload contains the fields message and weather. When a message field is present, Stackdriver Logging uses it as the summary of the log entry when the entry is not expanded.

For more information on log entry data formats, see Datatypes common to all logs.

Filter log entries

  1. In the filter box above the logs selector, type simple and press ENTER. You should see only the log entry, A simple entry.

  2. Remove the filter string you added and select the refresh icon (Jump to newest logs) above the logs selector. Both log entries reappear.

  3. At the right end of the filter box, select the disclosure icon and then select Convert to advanced filter. After the filter text that already appears in the advanced filter, add the following line:

    jsonPayload.weather:partly

  4. Select Submit filter. You should see only the log entry, My second entry:

    Advanced filter for log entries

For more information on filters, see Searching and filtering logs.

List log entries using the Logging API

  1. Go to the API reference page for the entries.list API method:

    Go to entries.list API page

  2. At the bottom or right-hand side of the page, you see a Try this API section that lets you run the API method.

  3. In the Request body section, fill in values for projectIds and filter as shown in the following screenshot. Use your own project ID. Use the same filter value shown in the screenshot, as resource.type=global corresponds to customized logs written by gcloud:

    Try this API

  4. Select Execute. You should see a response similar to the following:

    Response:
    {
     "entries": [
      {
       "textPayload": "A simple entry",
       "insertId": "2016-03-18|06:33:11.477796-07|10.95.75.135|-1308388662",
       "resource": {
        "type": "global"
       },
       "timestamp": "2016-03-18T13:33:11.456328306Z",
       "logName": "projects/my-gcp-project-id/logs/my-test-log"
      },
      {
       "insertId": "2016-03-18|06:34:05.690112-07|10.95.160.201|-670393401",
       "jsonPayload": {
        "weather": "partly cloudy",
        "message": "My second entry"
       },
       "resource": {
        "type": "global"
       },
       "timestamp": "2016-03-18T13:34:05.676109435Z",
       "logName": "projects/my-gcp-project-id/logs/my-test-log"
      }
     ]
    }
    

List log entries using the Cloud SDK

  1. Run the following gcloud command:

    gcloud beta logging read "resource.type=global"
    

    You should see output similar to the following:

    ---
    insertId: 2016-03-18|06:34:05.690112-07|10.95.160.201|-670393401
    jsonPayload:
      message: My second entry
      weather: partly cloudy
    logName: projects/my-gcp-project-id/logs/my-test-log
    projectNumber: '649517127304'
    resource:
      type: global
    timestamp: '2016-03-18T13:34:05.676109435Z'
    ---
    insertId: 2016-03-18|06:33:11.477796-07|10.95.75.135|-1308388662
    logName: projects/my-gcp-project-id/logs/my-test-log
    projectNumber: '649517127304'
    resource:
      type: global
    textPayload: A simple entry
    timestamp: '2016-03-18T13:33:11.456328306Z'
    

Clean up

To avoid incurring charges to your Google Cloud Platform account for the resources used in this quickstart:

  1. (Optional) To delete the log entries you created, run the following gcloud command:

    gcloud beta logging logs delete my-test-log
    

    If you do not delete your log entries, they will expire and be removed. See Quota Policy. If logs such as my-test-log have no entries, then the Logs Viewer does not display them.

What's next

  • See Logs Viewer for a more detailed discussion of the Logs Viewer.
  • See Exporting logs to learn how to export your log entries to Google Cloud Storage, Google Bigquery, and Google Cloud Pub/Sub.
  • See Logging Agent to learn how to collect log entries from your virtual machine instances in Stackdriver Logging.
  • See Audit Logs for your auditing and compliance needs.
  • See Stackdriver Logging API to learn how to read, write, and configure logs from your applications.

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Stackdriver Logging