Tail log entries

Demonstrates how to tail live log entries.

Documentation pages that include this code sample

To view the code sample used in context, see the following documentation:

Code sample


To learn how to install and use the client library for Logging, see the Logging Client Libraries.

const {Logging} = require('@google-cloud/logging');
const logging = new Logging();

 * TODO(developer): Replace logName with the name of your log.
const log = logging.log(logName);
console.log('running tail log entries test');

const stream = log
    filter: 'timestamp > "2021-01-01T23:00:00Z"',
  .on('error', console.error)
  .on('data', resp => {
    // If you anticipate many results, you can end a stream early to prevent
    // unnecessary processing and API requests.
  .on('end', () => {
    console.log('log entry stream has ended');

// Note: to get all project logs, invoke logging.tailEntries

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser