Viewing logs

This guide shows you how to search logs and view log entries with the Stackdriver Logging Logs Viewer.

Before you begin

You don't need a Workspace to use Logging, unless you are sending logs from Amazon Web Services (AWS) to Logging.

The Logs Viewer displays logs for a single Google Cloud Platform project. If you are using a Workspace, Logging doesn't combine the logs from the monitored projects. You must select a specific project to view its logs.

If you are using a Workspace and AWS, select the AWS connector project to see the AWS logs.

Getting started

  1. Go to the Stackdriver Logging > Logs (Logs Viewer) page in the GCP Console:

    Go to the Logs Viewer page

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

  3. Using the drop-down menus, select the resource whose logs you want to view.

If you cannot see any logs, see the Troubleshooting section below.

Logs Viewer query interfaces

There are two querying interfaces in the Logs Viewer:

  • The basic query interface lets you select logs from menus and has a simple search capability.
  • The advanced query interface lets you view log entries from multiple logs and has a more sophisticated search capability.

You can switch between these interfaces using the drop-down arrow (▾) at the far right of the search-query box in either interface.

The following screenshot shows the Logs Viewer's layout with the basic query interface. The screenshot displays log entries from a App Engine application:

Logs Viewer

The basic query interface has the following major components—indicated by red numbers in the screenshot above—some of which are shared with the advanced query interface:

  1. The window tabs let you stay on Logs (the Logs Viewer page), or choose between other Stackdriver Logging features: Metrics (see Logs-based metrics), Exports (see Exporting with the Logs Viewer), and Logs ingestion (see Logs exclusions).
  2. The search-query box in the basic query interface lets you query log entries by label or text search. The basic query is shown, and the drop-down arrow (▾) at the far right lets you switch to the advanced query interface or get a link to your query. Log queries are labelled as "filters" in the user interface, since they let you select a particular set of log entries.
  3. The basic selector menu lets you choose resources, logs, and severity levels to display:

    • Resources: The resources available in your current project.
    • Logs: The log types available for the current resources in your project.
    • Log severity: The log severity levels.
  4. The time-range selector drop-down menus let you query for specific dates and times in the logs.

  5. The streaming selector, at the top of the page, controls whether new log entries are displayed as they arrive.

  6. The log-entry table contains the log entries available according to your current queries and custom fields.

  7. The expander arrow (▸) in front of each log entry lets you look at the full contents of the entry. For more information, see Expand log entries.

  8. The View Options menu, at the far right, has additional display options.

  9. The Download logs menu, at the far right, lets you download a set of log entries. For details, see download log entries.

  10. The More (⋮) option, displayed with each log entry, lets you place a pin on the log entry, show the log entry in its resource context, and copy a URL for the log entry to the clipboard.

Lastly, the Logs Viewer uses the cursor position to highlight the associated log entry and to display a pin (📌) symbol next to the More (⋮) icon.

Scroll and stream logs

When you first open the Logs Viewer, you see enough recent log entries to fill the screen. When you scroll through your log entries, the Logs Viewer tries to fetch additional entries. The yellow bar above and below the logs lets you know if more log entries might be available.

The icons at the top of the screen control when the logs are refreshed:

  • Click the refresh icon (refresh) to retrieve the latest logs; scroll downwards to display them.
  • Click the play icon (play_arrow) to stream the latest logs. Streaming stops when you select a log entry or scroll through the logs display.
  • Click the pause icon (pause) to stop streaming.

Scroll to a time

You can query your log entries by time and date using the time-range selector menus below the search-query box.

Time-range selector

The default selection is Last hour. You can use the drop-down menu to select other time ranges or define a range:

  • Select Jump to time to query the logs to a particular date and time.
  • Select Custom to specify a custom range or a time zone.

To show the current log entries, click Jump to now.

In all cases, a selection causes the Logs Viewer to refresh the display. You can then scroll through, and inspect, the displayed log entries.

To reset the date and time to correspond to the most recently received log entry, click the Refresh or the Play icon.

Change time zone

You can select a time zone for your log entries:

  1. From the Last hour drop-down menu, select Custom.
  2. Click the expander arrow (▾) in either one of the new menus to open a drop-down calendar.
  3. In the Time Zone pane, select your preferred country and time zone.

Your selection causes the Logs Viewer to refresh the display and update the time zone for each log entry:

Customize time zone

Expand log entries

The log-entry table displays a summary line for each log entry by default.

Log entry summary line

The log entry summary line might contain highlighted fields. For example, custom fields are highlighted.

The fields included in the summary line are selected as subsets of the log entry fields. Certain fields are shown by default if they meet one or more of these criteria:

  • The log entry has a well-known type such as an App Engine request log.
  • The log entry contains the httpRequest field.
  • The log entry has a payload containing a field named message.

To see the full details for one log entry, click the expander arrow (▸) at the front of the summary line. To see the full details in a structured view for all the log entries available with your current query, click the View Options menu at the far right and then select Expand All:

View options menu

You can select Collapse All to collapse all expanded log entry details.

When you expand a summary line for a log entry, the Logs Viewer displays a structured (JSON) representation:

Structured request log entry

For a description of the fields in a log entry, see the LogEntry type.

Add custom fields

Custom fields are fields within log entries that you can specify to be included in the summary line. These fields are populated, and highlighted in blue, whenever they are available in your log entries.

Custom fields in summary line

There are two ways you can add custom fields to your log-entry table summary lines:

  • In an expanded log entry, click on a field within the JSON representation. In the resulting panel, select Add field to summary line:

Add field to summary line

  • From the Viewing Options menu at the top far right of the Logs Viewer, select Add custom fields (if you have existing custom fields in this project, this option is Modify custom fields). In the resulting panel, add the desired JSON key and click Save. You can add multiple keys by separating them with a comma. To reorder the appearance of your custom fields in your summary lines, reorder the text in this panel and click Save.

Add JSON field to summary line

There are 2 ways you can remove custom fields from your log-entry table summary lines:

  • From any summary line that features the custom field that you wish to remove, click on the field and select Remove field from summary line.
  • From the Viewing Options menu at the top far right of the Logs Viewer, select Modify custom fields. In the resulting panel, delete the JSON keys that you wish to remove and click Save.

Custom fields are added to your current URL and remain as long as you are using that URL or are within the same browser session. You cannot set them at a global level and they cannot be saved per user or per GCP project.

Default fields cannot be removed from the log-entry table.

Pin a log entry

If you have identified an interesting log entry and want to investigate nearby entries, you can place a pin on the log entry. After the log entry is pinned, you can change the query and the Logs Viewer automatically centers the search around the pinned entry. Pinning gives you the ability to examine a log entry in the context specified by a query you define. After a log is pinned, its background is changed and a pin is shown:

Pinned Log Entry

To pin a log entry, click its pin or click More (⋮) and select Pin this log entry.

When you place a pin on a log entry, that pin is visible only to you. Any other users viewing the same log entries won't see your pin or have their view modified in any way.

Pinning a log entry doesn't change the query interface, the query settings, or refresh the displayed contents. You determine the query settings and when to refresh the Logs Viewer display. You can modify the query settings and refresh the display as many times as you want without affecting the pin.

Pinning a log entry stops streaming if it is currently enabled.

If a log entry is pinned, you can move or remove the pin:

  • To move the pin to a different log entry, on the new log entry click its pin icon or click More (⋮) and select Move pin to this log entry.

  • To remove the pin from a log entry, click its pin symbol or click More (⋮) and select Remove pin from this log entry.

If you enable streaming while a log entry is pinned, the Logs Viewer removes the pin.

Show similar logs

You can click the value of an individual field in the expanded log entry view and then either show or hide all log entries with the same value:

Show matching entries

When you do this, the Logs Viewer changes to the advanced query interface. To modify the search, edit the query and click Submit Filter. For more information, see the Advanced query interface.

Additionally, you can correlate App Engine request log entries and then view them in a nested structure. For details, see Viewing related request log entries and select your runtime language.

Show latency details

New For App Engine request logs, the Logs Viewer provides a link to Stackdriver Trace for easy viewing of the log entry's latency details.

To show the menu of latency-related options for a log entry, identify the protoPayload.latency field:

Show protoPayload.latency

Click on the latency value:

Show latency options

The first two options in the menu restrict the log entries shown to those with higher or lower latencies. The last option in the menu restricts the log entries to those that contain trace details viewable by Stackdriver Trace. Specifically, the last option restricts the log entries to those where View trace details is enabled.

Viewing latency details in Stackdriver Trace

For certain App Engine request logs, the option View trace details is enabled. When enabled, click this option to open Stackdriver Trace and display the latency details of the log entry:

Show trace timeline

Show in resource context

If you have identified an interesting log entry and want to identify other log entries associated with the same resource type, click More (⋮) at the far right of the line and select the option Show in resource context:

Show context

In response to your action, the Logs Viewer:

  1. Pins the log entry.
  2. Switches to the advanced query interface and replaces the query contents with a query on the resource type.
  3. Refreshes the display. The pinned log entry is shown towards the bottom of the display.

Shown in context

Share a log entry

To share a log entry, click More (⋮) and select Copy link to log entry to clipboard. This action causes the Logs Viewer to generate a unique URL for the log entry and copy the URL into the clipboard.

Selecting logs

Use the menus and search-query box to find the logs you want to see:

  • Select a resource type and instance whose logs you want to see. You can look at all instances of this resource type, or select a particular instance. In the screenshot above, G​C​E VM instance (all instances) is selected. For a list of resource types, see Monitored resource list.

  • Select the named logs you want to see from the second menu, or select All logs. The menu shows the logs that are in use by the selected resource instances.

  • Select the lowest severity level you want to see in the third menu. Selecting Any log level also shows log entries that have no assigned severity.

  • Select the time range you want to see from the fourth menu, or select Jump to now from the fifth menu.

As you change your menu selections, you see the matching log entries.

Menu notes:

  • Only the resource types, instances, and log names that are present in your project are shown in the menus. It might take a short time for the menus to be updated after adding a new resource type or instance, or writing to a new log.

  • In the basic query interface, you can look at only log entries from one resource type at a time. The advanced query interface permits multiple resource types.

  • You won't see any logs if you browse to a time before your current retention window. For more information, see Logs retention periods.

Download log entries

With a few clicks, you can download, in JSON or CSV format, all of the log entries stored in the Logs Viewer's working memory. For performance reasons, the Logs Viewer attempts to load 100 log entries at a time and retains no more than 300 log entries in its working memory. These values aren't configurable.

To download log entries, click the Download logs menu, which is located at the top far right of the Logs Viewer. In the download dialog, select JSON or CSV for the Log entry format, then click Download:

Show Download Details

To view JSON- or CSV-formatted log entries in a web page, follow the same steps as for a download but select View In New Tab.

Searching with the Logs Viewer

You can further narrow your searches using queries in both the basic and advanced query interfaces. The advanced query interface contains most of the same features as the basic query interface, but has more sophisticated search capabilities.

Differences between basic and advanced queries

The syntax for the basic and advanced query interfaces is different. The basic query interface is built with assumptions, for example, all searches are case insensitive, that are invalid for the advanced query interface.

The next few sections highlight key differences in the syntax between these two interfaces.

Keyword "text:"

The Logs Viewer shows text searches in the basic query by prefixing the text with the label text:. Don't use the text: label with advanced queries.

The following table shows equivalent text searches:

Logs Viewer basic query Advanced logs query with the same meaning
text:"one two" "one two"
text:three three
text:n=5 "n=5" (quotations required)

If you accidentally use text: in the advanced query, you search for a match in a field called text, which doesn't exist.

Field names

The basic query interface has built-in field names for certain logs, including the App Engine request log. Those field names don't exist in advanced queries.

The following table shows an equivalent field search for an App Engine request log:

Basic query Advanced query
querystring:var=3 protoPayload.resource:"var=3"
status:400..405 protoPayload.status >= 400 AND protoPayload.status <= 405

If you use querystring:var=3 in the advanced filter, you search for a field named querystring, which doesn't exist. Therefore, the Logs Viewer doesn't find any matching log entries.

Substring matches

In the basic query interface, all searches are case-insensitive substring matches. That is, the searches text:abc or somefieldname:abc matches log entries containing abc, xyabcyx, and ABc. In advanced log queries, you must use the "has" search operator (:) for the same behavior.

For an exact match, use the equals operator (=). The comparison field=abc requires that field contain exactly abc, in any letter case. That search cannot be expressed in the basic query interface.

AND and OR

In the basic query interface, two comparisons using the same field name (or text:) are implicitly joined with OR, whereas comparisons with different labels are joined by AND. In advanced logs queries, all comparisons are joined by AND unless OR is specified explicitly. You can also use parentheses to group comparisons. The following table shows equivalent searches in the two query interfaces:

Basic query search Advanced query search
text:abc querystring:def text:xyz protoPayload.resource:"def" AND ("abc" OR "xyz")

Search performance

Here are some tips to increase your search performance:

  • Search for specific values of indexed fields, like the log entry's name, resource type, and resource labels. In the basic query interface, you do this with menu selections. In the advanced query interface, use conditions like the following:

    resource.type = "gce_instance"
    logName = "projects/[PROJECT_ID]/logs/cloudaudit.googleapis.com%2Factivity"
    resource.labels.module_id="default"
    resource.labels.instance_id="1234567890"
    
  • Choose exact matches over substring searches. Especially on index fields, partial matches are slower. In the basic query interface, all text searches are partial matches. In the advanced query interface, favor tests using equality operator (=) rather than using "has" (:).

  • Shorten the time period searched. You cannot do this in the basic query interface, but in the advanced query interface you can specify a time range:

    timestamp >= "2016-11-29T23:00:00Z" AND timestamp <= "2016-11-29T23:30:00Z"
    

For more information on performance, see Finding log entries quickly.

Saved searches

You can save a basic or advanced logs filter search to a Saved Searches library and give the search a name and description. Basic filters are converted to advanced filters when saved to the Saved Searches library. You can name, manage, and share saved searches in your library. You are limited to 100 saved searches per user, per Google Cloud Platform project.

To create a saved search, complete the following steps:

  1. Filter for the logs you want to save by creating an advanced logs filter.

  2. Click Save Search.

    Saved searches button

  3. Name and describe the filter you created and then click Save to library.

    The Filter Preview pane displays the filter criteria for the saved search.

View saved searches

To view your saved searches, click Show Library.

Saved searches library

Edit saved searches

To apply your saved filter, delete the filter, or preview its notation, complete the following steps:

  1. View your saved searches by clicking Show Library.

  2. To preview or delete a saved search, click More .

    Edit saved searches

    You cannot change the filter criteria for a saved search once it's created. If you want to change the filter criteria of a saved search, delete the saved search and then create a new saved search with your desired criteria.

Share saved searches

You can share your saved searches with users who have Cloud Identity and Access Management permissions on your project.

To share a saved search, complete the following steps:

  1. View your saved searches by clicking Show Library.

  2. Click More and then Preview.

  3. Click Copy link to Filter.

    Share a saved search

Troubleshooting

This section provides instructions for troubleshooting common issues found when interacting or searching with the Logs Viewer.

GCP project selection

To select a GCP project from anywhere in the Google Cloud Platform Console, including from the Logs Viewer, use the project selector at the top of the page:

GCP Console project selector

GCP project ID

To retrieve the GCP project's ID from from anywhere in the Google Cloud Platform Console, including from the Logs Viewer, expand your list of projects at the top of the page and look in the ID column:

GCP Console project ID information

There aren't any logs!

If you don't see any logs, then check the following:

  • Is the correct project selected at the top of the page? If not, use the drop-down menu at the top of the page to select a project. You must select the project whose logs you want to see.

  • Does your project have any activity? Even if the project is new, it should have activity or audit logs recording the fact that it was created. You can get more logs by going through the Quickstart.

  • Is the time range too narrow? You can use the drop-down menus below the search-query box to select other time ranges or define a Custom range. Select Jump to time to query the logs to a particular date and time, or use the Jump to now menu to see current log entries.

  • Is the time range incorrect? If you are writing a query that includes a timestamp, you must select No limit from the time-range selector below the search-query box.

My search isn't working!

If you aren't sure why your search isn't working in the basic query interface, briefly switch to the advanced query interface:

  1. Select Convert to advanced filter in the ▾ menu at the end of the search-query box.
  2. Look at the advanced query to see if it is what you intended.
  3. Return to the basic query interface by using the browser's Back button.

Here are some other reasons you might not see all the log entries you expect:

  • You cannot see log entries that are older than the Logging retention period. See Logs retention periods for the logs retention period in effect.

  • During periods of heavy load there could be delays in sending logs to Logging or in receiving and displaying the logs.

  • The Logs Viewer doesn't show log entries that have timestamps in the future until the current time has "caught up" with them. This is an unusual situation, probably caused by a time skew in the application sending the logs.

What's next

Kunde den här sidan hjälpa dig? Berätta:

Skicka feedback om ...

Stackdriver Logging
Behöver du hjälp? Besök vår supportsida.