Streaming and live tailing log entries

This document describes how to view your log entries in real time by streamingand live tailing.Streaming logs lets you view log entries in real time and is available in theLogs Explorer.Live tailing lets you view log entries in real time and is available as thegcloud CLIcommandgcloud alpha logging tailand as the Cloud Logging API methodentries.tail.

When you view and analyze your logs using the Logs Explorer,gcloud logging read, or the API methodentries.list, you're viewing log entries thatCloud Logging has stored. When you streamor live tail log entries, you're viewing log entries as yourapplications write them to the Cloud Logging API.

Note: If your data is managed through anAssured Workloads environment,then this feature might be impacted or restricted. For information, seeRestrictions and limitations in Assured Workloads.

Stream logs in the Logs Explorer

In the Logs Explorer, you can view your logs data in real time usingStream logs. When you useStream logs, you can add a queryto stream only those logs that match the query. To stream logs, do the following:

  1. In the Google Cloud console, go to theLogs Explorer page:

    Go toLogs Explorer

    If you use the search bar to find this page, then select the result whose subheading isLogging.

  2. In theQuery field, enter a query and then clickStream logs.

    As Logging writes the logs data, only logs that match thequery are shown in theQuery results pane.If a query isn't provided, then Logging shows the recentlystored log entries.Logs continue streaming until you select the scroll bar on the logs panel.When streaming has stopped, aRestart streaming button is shown.

    For information about queries, seeBuild queries in the Logs Explorer.

Use live tailing in the Google Cloud CLI

Preview

This product or feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of theService Specific Terms. Pre-GA products and features are available "as is" and might have limited support. For more information, see thelaunch stage descriptions.

Live tailing lets you view your log entries in real time as Cloud Loggingwrites them, by using either the Google Cloud CLI or the Cloud Logging API.

Live tailing isn't supported for log buckets withfield-level access controls, however youcanstream logs forthose buckets in the Logs Explorer.

For information on the API method for live tailing, seetheentries.tail method.

Installinggcloud alpha logging tail

To usegcloud alpha logging tail, you need to have Python 3 andthegrpcio Python package installed.

For instructions on how toinstall Python, see thePython page.For instructions on how to install the Python package manager,pip, that isneeded to install thegrpcio package, seeThe Python Package Installer page.

Complete the following steps to installgcloud alpha logging tail:

  1. Verify that you have the Google Cloud CLI installed. For instructions on howto install the Google Cloud CLI, seeInstalling Google Cloud CLI.

  2. Verify that you're using version 302.0.0 or greater of thegcloud CLI.

    gcloud version

    For instructions on updating the gcloud CLI, seegcloud components update.

  3. Install the gcloud CLI alpha components:

    gcloud components install alpha
  4. For MacOS, Linux, and Cloud Shell users:

    1. Install gRPC client libraries:

       sudo pip3 install grpcio
    2. Set the environment variableCLOUDSDK_PYTHON_SITEPACKAGES to any value:

      exportCLOUDSDK_PYTHON_SITEPACKAGES=1
      Note: By default, the Google Cloud CLI ignores Python libraries installedon your local system. To allow the Google Cloud CLI to use thegrpciolibrary, you need to enable site packages. To enable site packages,set theCLOUDSDK_PYTHON_SITEPACKAGES environment variable to1.With site packages enabled, the gcloud CLI can use extralibraries outside of thegoogle-cloud-sdk/lib directory.
  5. Use the following commands to set your Google Cloud project ID and toauthenticate:

    gcloud config set projectPROJECT_IDgcloud auth login

    To get the project ID, seeCreating and managingprojects.

  6. Verify thatgcloud alpha logging tail is installed by running the followingcommand:

    gcloud alpha logging tail

    The command displays the following message:

    Initializing tail session.

    You are now viewing the log entries for your Google Cloud project as Loggingwrites them.

    Log entries during a live-tail session.

For more information on using live tailing, see thegcloud alpha logging tail reference guide.

Buffering and ordering

Because Logging can receive log entries out of chronologicalorder, live tailing provides a buffer-window setting so you can balancethe tradeoff between viewing the log entries as they are being written andviewing them in ascending order. You can set the buffer windowbetween0 and60 seconds.

Note the following characteristics of the buffer window:

  • The default buffer window is two seconds.

  • Logging delays writing the log entries to log buckets for theduration of the buffer window.

  • If a log entry is written outside of the buffer window, thenLogging returns the log entries as they are received.

When configuring the buffer window, you make a tradeoff betweenviewing logs as they are written and viewing the entries out of order.

Buffer windowTradeoff
0 secondsNewest log entries returned, but with more likelihood of them being out of order.
60 secondsA delay of 60 seconds before seeing the entries returned, but most of the logs are returned in ascending order.

Limits and quotas

The following table lists the limits and quotas for live tailing:

Limits and quotasValue
Entries returned per minute60,000
If more than 60,000 entries match a filter, then Logging returns the count of entries in the response.
Open live-tailing sessions per Google Cloud project10

Client limitations

For a Google Cloud project that writes lots of entries quickly, your clientmight be unable to consume them as quickly as they're being written. Inthis case, Logging limits the total number of entries sent,prioritizing the most recent entries. At the end of the tail session,Logging returns the number of entries that were not displayeddue to the limits of the client.

Use live tailing with client libraries

Preview

This product or feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of theService Specific Terms. Pre-GA products and features are available "as is" and might have limited support. For more information, see thelaunch stage descriptions.

Live tailing lets you view your log entries in real time as Cloud Loggingwrites them. For information on the API method for live tailing, seetheentries.tail method.

Live tailing isn't supported for log buckets withfield-level access controls, however youcanstream logs forthose buckets in the Logs Explorer.

This sample demonstrates live tailing log entries of a given logger.

Go

To learn how to install and use the client library for Logging, seeLogging client libraries.

To authenticate to Logging, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

import("context""fmt""io"logging"cloud.google.com/go/logging/apiv2""cloud.google.com/go/logging/apiv2/loggingpb")// tailLogs creates a channel to stream log entries that were recently ingested for a projectfunctailLogs(projectIDstring)error{// projectID := "your_project_id"ctx:=context.Background()client,err:=logging.NewClient(ctx)iferr!=nil{returnfmt.Errorf("NewClient error: %w",err)}deferclient.Close()stream,err:=client.TailLogEntries(ctx)iferr!=nil{returnfmt.Errorf("TailLogEntries error: %w",err)}deferstream.CloseSend()req:=&loggingpb.TailLogEntriesRequest{ResourceNames:[]string{"projects/"+projectID,},}iferr:=stream.Send(req);err!=nil{returnfmt.Errorf("stream.Send error: %w",err)}// read and print two or more streamed log entriesforcounter:=0;counter <2;{resp,err:=stream.Recv()iferr==io.EOF{break}iferr!=nil{returnfmt.Errorf("stream.Recv error: %w",err)}fmt.Printf("received:\n%v\n",resp)ifresp.Entries!=nil{counter+=len(resp.Entries)}}returnnil}

Java

To learn how to install and use the client library for Logging, seeLogging client libraries.

To authenticate to Logging, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

importcom.google.cloud.logging.LogEntry;importcom.google.cloud.logging.LogEntryServerStream;importcom.google.cloud.logging.Logging;importcom.google.cloud.logging.Logging.TailOption;importcom.google.cloud.logging.LoggingOptions;publicclassTailLogEntries{publicstaticvoidmain(String[]args)throwsException{// TODO(developer): Optionally provide the logname as an argument.StringlogName=args.length >0?args[0]:"";LoggingOptionsoptions=LoggingOptions.getDefaultInstance();try(Logginglogging=options.getService()){// Optionally compose a filter to tail log entries only from specific logLogEntryServerStreamstream;if(logName!=""){stream=logging.tailLogEntries(TailOption.filter("logName=projects/"+options.getProjectId()+"/logs/"+logName));}else{stream=logging.tailLogEntries();}System.out.println("start streaming..");for(LogEntrylog:stream){System.out.println(log);// cancel infinite streaming after receiving first entrystream.cancel();}}}}

Node.js

To learn how to install and use the client library for Logging, seeLogging client libraries.

To authenticate to Logging, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

const{Logging}=require('@google-cloud/logging');constlogging=newLogging();/** * TODO(developer): Replace logName with the name of your log. */constlog=logging.log(logName);console.log('running tail log entries test');conststream=log.tailEntries({filter:'timestamp > "2021-01-01T23:00:00Z"',}).on('error',console.error).on('data',resp=>{console.log(resp.entries);console.log(resp.suppressionInfo);// If you anticipate many results, you can end a stream early to prevent// unnecessary processing and API requests.stream.end();}).on('end',()=>{console.log('log entry stream has ended');});// Note: to get all project logs, invoke logging.tailEntries

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-18 UTC.