View logs routed to Pub/Sub Stay organized with collections Save and categorize content based on your preferences.
This document explains how you can find log entries that you routed fromCloud Logging toPub/Sub topics, which occursin near real-time.We recommend using Pub/Sub for integratingCloud Logging logs withthird-party software.
When you route log entries to a Pub/Sub topic,Loggingpublishes each log entry as a Pub/Sub message as soon asLogging receives that log entry. Routed log entries aregenerally available within seconds of their arrival to Logging,with 99% of log entries available in less than 60 seconds.
Before you begin
For a conceptual discussion of sinks, seeOverview of routing and storage models: Sinks.
For instructions on how to route your log entries, seeRoute logs to supported destinations.
View logs
To view your logs as they are streamed through Pub/Sub,do the following:
In the Google Cloud console, go to theTopics page:
If you use the search bar to find this page, then select the result whose subheading isPub/Sub.
Find or create a subscription to the topic used in the log sink, and pull alog entry from it. You might have to wait for a new log entry to bepublished.
Logs organization
Thedata field of each message is a base64-encodedLogEntryobject.As an example, a Pub/Sub subscriber might pull the followingobject from a topic that is receiving log entries.The object shown contains a list with a single message, althoughPub/Sub might return several messages if several log entries areavailable.Thedata value (about 600 characters) and theackId value(about 200 characters) have been shortened to make the example easier to read:
{ "receivedMessages": [ { "ackId": "dR1JHlAbEGEIBERNK0EPKVgUWQYyODM...QlVWBwY9HFELH3cOAjYYFlcGICIjIg", "message": { "data": "eyJtZXRhZGF0YSI6eyJzZXZ0eSI6Il...Dk0OTU2G9nIjoiaGVsbG93b3JsZC5sb2cifQ==", "attributes": { "compute.googleapis.com/resource_type": "instance", "compute.googleapis.com/resource_id": "123456" }, "messageId": "43913662360" } } ]}If you decode thedata field and format it, you get the followingLogEntry object:
{ "log": "helloworld.log", "insertId": "2015-04-15|11:41:00.577447-07|10.52.166.198|-1694494956", "textPayload": "Wed Apr 15 20:40:51 CEST 2015 Hello, world!", "timestamp": "2015-04-15T18:40:56Z", "labels": { "compute.googleapis.com\/resource_type": "instance", "compute.googleapis.com\/resource_id": "123456" }, "severity": "WARNING" }}Third-party integration with Pub/Sub
You route your log entries to a Pub/Sub topic. The thirdparty receives your log entries by subscribing to the same topic.Logging supports logging integration with third parties, suchas Splunk or Datadog. For a current list of integrations,seePartners for Google Cloud Observability integrations.
To perform the integration, expect to do something like the following:
In your project where your log entries originate, createyour Pub/Sub topic with adefault subscription:
Enable the Pub/Sub API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission.Learn how to grant roles.In the Google Cloud console, go to theTopics page:
If you use the search bar to find this page, then select the result whose subheading isPub/Sub.
ClickCreate topic.
In theTopic ID field, enter an ID for your topic. For example,
projects/my-project-id/topics/my-pubsub-topic.Each message sent to the topic include the timestamp of the routedlog entry in the Pub/Sub message
attributes; forexample:"attributes": { "logging.googleapis.com/timestamp": "2024-07-01T00:00:00Z"}Retain the optionAdd a default subscription. Don't select any otheroption.
ClickCreate topic.
In your project where your log entries originate, configureLogging to route log entries to your topic:
In the Google Cloud console, go to theLog Router page:
If you use the search bar to find this page, then select the result whose subheading isLogging.
- ClickCreate Sink,enter a name and description for the sink, and then clickNext.
- In theSink Service menu, selectCloud Pub/Sub topic,select the Pub/Sub topic, and then clickNext.
- Select the log entries to include in the sink and then clickNext.
- Optional: Select the log entries to exclude.
ClickCreate Sink.
A dialog with the messageSink created appears. Thismessage indicates that your sink was successfully created withpermissions to route future matching log entries to the destinationyou selected.
Grant the principal specified in the sink's writer identitythe following IAM roles:
Logs Writer (
roles/logging.logWriter)Pub/Sub Publisher (
roles/pubsub.publisher)
For more information about obtaining the writer identity and granting arole, seeSet destination permissions.
Cloud Logging is now sending log entries to your Pub/Subtopic.
Create the subscription.
For example, if you use Dataflow topull the data from your Pub/Sub topic and send it toDatadog, then you need to perform two steps:
Create, or obtain, a service account, and then grant it theIAM roles necessary to subscribe to your topic. At aminimum, the service account requires the following roles:
- Pub/Sub Subscriber (
roles/pubsub.subscriber) - Dataflow Admin (
roles/dataflow.admin) - Dataflow Worker (
roles/dataflow.worker)
For more information, see the following documents:
- Pub/Sub Subscriber (
Create a job from a template, and then run that job.For this example, you would use thePub/Sub to Datadog template.
Your third party should begin receiving the log entries right away.
For an exploration of common logs routing scenarios usingPub/Sub, seeScenarios for exporting Cloud Logging data: Splunk.
Troubleshooting
If log entries seem to be missing from your sink's destination or you otherwisesuspect that your sink isn't properly routing log entries, then seeTroubleshoot routing logs.
Pricing
For pricing information, seeGoogle Cloud Observability pricing page. If you route log data toother Google Cloud services, then see the following documents:
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.