The Stackdriver Logging API lets you programmatically read and write log entries, set up exclusions, create logs-based metrics, and manage export sinks. This section provides reference pages for the API.
- For reference documentation for the REST version of the API, see REST reference.
- For reference documentation for the gRPC version of the API, see gRPC reference.
Ways to interact with the API
Users typically invoke the API by using a command-line interface or a client library written to support a high-level programming language.
For the command-line interface to the Logging API, see the
For instructions on setting up client libraries and authorizing the Logging API, with sample code, see Client libraries.
To try out the API without writing any code, you can make calls from the REST reference pages from your browser using the API Explorer. API Explorer is a widget attached to the REST API reference page for a method. It appears as a panel with the title Try this API. Using the API Explorer describes using the widget with the Stackdriver Monitoring API; it works the same way for the Logging API.
Tips for using the API
Bulk processing of log entries
The method you use to retrieve log entries is
this method isn't intended for high-volume retrieval of log entries. Using
this method in this way might quickly exhaust your quota for read requests.
If you need to perform bulk processing on log entries, the recommended approach is to create a Cloud Pub/Sub sink that exports the log entries you want to process to a Cloud Pub/Sub topic, and then consume the log entries from there.
This approach has the following advantages:
- It doesn't exhaust your read-request quota. For more on quotas, see Logging usage limits.
- It captures log entries that might have been written out of order, without workarounds to seek back and re-read recent entries to ensure nothing was missed.
- It automatically buffers the log entries if the logs consumer becomes unavailable.
- It doesn't require you to send the logs to Stackdriver Logging storage, so they don't count against your logs-ingestion allowance. For more information, see Pricing: Logging details.
The approach of creating Cloud Pub/Sub sinks for logs exports can be applied to a variety of analytics platforms. The following documents illustrate this approach with different target platforms: