If you are not familiar with exporting logs in Stackdriver Logging, see Overview of Logs Export. In summary, you export logs by creating one or more sinks that include a logs filter and a destination. As Stackdriver Logging receives new log entries, they are compared against each sink. If a log entry matches a sink's filter, then a copy of the log entry is written to the destination.
To learn how exported logs are formatted and organized, see Using Exported Logs.
Advantages and limitations
The Logs Viewer has the following advantages over using the Stackdriver Logging API:
- The Logs Viewer shows all of your sinks in one place.
- The Logs Viewer shows you which log entries are matched by your sink filter before your create a sink.
- The Logs Viewer can create and authorize destinations for your sinks.
However, the Logs Viewer can only create or view sinks in projects. To create sinks in organizations, folders, or billing accounts, see Aggregated Exports.
Before you begin
Project: You must have a Google Cloud Platform project with logs that you can see in the Logs Viewer.
You must also have the Owner or the Logging/Logs Configuration Writer IAM roles in the project to create, delete, or modify a sink. For getting-started information, see the Stackdriver Logging Quickstart and Permissions and roles for more information.
Understanding the user interface
Sinks are configured in the Exports page of the Logs Viewer.
The following screenshot shows an example of the Logs Viewer's Exports page, where several log sinks are already configured:
You will see the message No Log sinks are configured, instead of the list shown above, if you have not yet configured any log sinks.
The information shown corresponds to some of the sink properties described in Overview of Logs Export:
- Sink Name: The sink's identifier in the current project.
- Destination: Where the exported log entries will go.
- Writer Identity: The service account that Stackdriver Logging uses to write log entries to the destination. This service account must have permission to write to the sink's destination.
Each sink has the following options in its right-side More menu:
- Edit sink: Lets you update the sink's parameters.
- Delete sink: Deletes the sink.
- View filter: Displays the sink's filter. Clicking Edit will let you update the sink.
To create an export sink, click the Create Export button at the top of the Exports page. You can also access this button at the top of the Logs Viewer page.
If your account lacks permission to create exports for the project, this button is disabled. See Permissions and roles for more information.
The following screenshot shows the Edit Export panel with some fields filled in:
To create a sink, fill in the Edit Export panel as follows:
(filter): Enter an advanced logs filter. You don't need quotation marks around the filter and you can use multiple lines. The initial filter is determined by the log entries being displayed when you click Create Export.
Whenever you edit the filter, press Submit Filter to display the matched log entries in the area at the bottom of the page. Press the Jump to newest logs icon at the top of the page to fetch the most recent logs.
If you wish to use the basic viewing interface to select the logs, use the ▾ menu at the right side of the search-filter box.
Sink name: Enter the identifier you want to assign to the sink.
Sink Service: Select a destination service: Cloud Storage, Cloud Pub/Sub, BigQuery or Custom Destination.
A custom destination still has to be in Cloud Storage, BigQuery, or Cloud Pub/Sub, but allows you to send logs to a sink in a different project.
- Cloud Storage: Select or create the particular bucket to receive the exported logs.
- Cloud Pub/Sub: Select or create the particular topic to receive the exported logs.
- BigQuery: Select or create the particular dataset to receive the exported logs.
- Custom Destination: Add the Cloud Storage, Cloud Pub/Sub, or BigQuery project as a string. For information on project name formatting, see Sink properties.
Click Create Sink to create the sink.
As part of creating the sink, Stackdriver Logging attempts to grant the sink's writer identity permission to write to your destination. If you are exporting to a destination in a project other than the one owning your logs, then an administrator of the new destination must grant permission. You should send the administrator the sink's writer identity, which is listed with the sink in the Exports page.
New log entries that match your sink will start being exported. Log entries going to BigQuery or Cloud Pub/Sub are streamed to those destinations immediately. Log entries going to Cloud Storage are batched and sent out approximately every hour. For more information, see Using exported logs.
If Stackdriver Logging encounters errors when trying to export logs to your destination, the errors appear in your project's Activity Stream. Select Activity at the top of your project's home page in Google Cloud Platform Console. To diagnose common errors, see Troubleshooting.
To update a sink, select the Edit sink command in the More menu to the right of the sink's name. You can change any of the following parameters:
To change other parameters of your sinks, use the projects.sinks.update API method.
To delete a sink, select the sink in the Exports page and press Delete at the top of the page. Alternatively, select Delete sink from the More menu to the right of the sink's name.
This section describes how you can grant Stackdriver Logging permission to write exported logs to your sink's destination.
When you create a sink, Stackdriver Logging creates a new service account for the sink, called a unique writer identity. Your destination must permit this service account to write log entries. To set up this permission, follow these steps:
Create the new sink in the Logs Viewer, the
gcloud loggingcommand-line interface, or the Stackdriver Logging API.
If you created your sink in the Logs Viewer and you have Owner access to destination, then the Logs Viewer should have set up the needed permission on your behalf. If it did so, you are done. If not, continue.
Obtain the sink's writer identity—an email address—from the new sink:
- If you are using the Logs Viewer, you can see the writer identity in the sink listing on the Exports page.
- If you are using the Stackdriver Logging API, you can get the writer identity from the LogSink object.
- If you are using
gcloud logging, you can see the writer identities when you list your sinks.
If you have Owner access to the destination, then add the service account to the destination in the following way:
- For Cloud Storage destinations, add the sink's writer identity to your bucket and give it the Storage Object Creator role.
- For BigQuery destinations, add the sink's writer identity to your dataset and give it the BigQuery Data Editor role.
- For Cloud Pub/Sub, add the sink's writer identity to your topic and give it the Pub/Sub Publisher role.
This completes the authorization.
If you do not have Owner access to the destination, then send the writer identity service account name to someone who has that ability. That person should then follow the instructions in the previous step to add the writer identity to the destination.
If a sink tries to export a log entry but does not have the needed permission to the destination, it will report an error and skip the log entry. This will continue until the permission is granted, at which time the sink begins exporting new log entries.
There is an unavoidable delay between creating the sink and using the sink's new service account to authorize writing to the destination. You can choose to simply ignore any error messages from the sink during the delay.
This section lists some possible errors and unexpected results, and explains what to do about them.
Errors from sinks appear in the Activity Stream for the project or other resource where the sink was created. See the Activity Stream in the resource's home page in GCP Console.
|Your new log entries are exported but your older log entries are not exported.||Stackdriver Logging only exports log entries that are received after the export has been set up.||Use the entries.list API method to retrieve your older log entries and use the destination service's API to write the log entries to the export destination.|
Errors exporting to Cloud Storage
The following table lists the most common errors when you configure Stackdriver Logging to export logs to Cloud Storage:
|Permissions on bucket [YOUR_BUCKET] do not allow the logs group to create new objects.||The sink's writer identity does not have enough permissions to the bucket.||Add the necessary permissions to the bucket or update your sink to use a different bucket. See Destination permissions.|
|No bucket with name: [YOUR_BUCKET].||There might be an error in the bucket name, or the bucket might have been deleted.||Update your sink with the correct bucket destination.|
Errors exporting to BigQuery
The following table lists the most common errors when you configure Stackdriver Logging to export logs to BigQuery:
|Permissions on dataset [YOUR_DATASET] do not allow the logs group to create new tables.||The sink's writer identity does not have enough permissions to the bucket.||Add the permission to the dataset. See Destination permissions.|
|No dataset with name: [YOUR_DATASET].||You might have an error in your sink's destination or someone might have deleted the dataset.||Either re-create the dataset or update the export sink to use a different dataset.|
|Logs streamed to table [YOUR_TABLE] in dataset [YOUR_DATASET] do not match the table schema.||You are trying to export logs that are incompatible with the current table's schema.||Make sure that your log entries match the table's schema. Common issues include sending log entries with different data types. For example, one of the fields in the log entry is an integer, while a corresponding column in the schema has a string type. The activity stream contains a link to one of the invalid log entries. After you fix the source of the error, you can rename your current table and let Stackdriver Logging create the table again.|
|Per-table streaming insert quota has been exceeded for table [YOUR_TABLE] in dataset [YOUR_DATASET].||You are exporting too many log entries too quickly. See the BigQuery default quota limits, which apply to logs streaming.||Decrease the amount of log data your sink generates. You can update your sink's filter to match fewer log entries or use the sample() function.|
|Logs streamed to partitioned table [YOUR_TABLE] are outside the permitted time boundaries.||BigQuery does not accept logs that are too far in the past or future.||Logs outside permitted time boundaries cannot be exported with sinks. You can export those logs to Cloud Storage and use a BigQuery load job instead. See BigQuery documentation for further instructions.|
Errors exporting logs to Cloud Pub/Sub
The following table lists the most common errors when you configure Stackdriver Logging to export logs to Cloud Pub/Sub:
|[ACCOUNT] needs edit permission on [PROJECT] to publish to [TOPIC]||The sink's writer identity does not have enough permissions to the bucket.||Add the necessary permissions to your project. See Destination permissions.|
|Topic [TOPIC] does not exist.||You might have deleted the topic that was configured to receive your exported logs.||Either re-create the topic with the same name, or change the export configuration to use a different topic.|