List logs

Stay organized with collections Save and categorize content based on your preferences.

Demonstrates how to list the names of available Logs.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

Java

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

import com.google.api.gax.paging.Page;
import com.google.cloud.logging.Logging;
import com.google.cloud.logging.LoggingOptions;

public class ListLogs {

  public static void main(String... args) throws Exception {

    try (Logging logging = LoggingOptions.getDefaultInstance().getService()) {

      // List all log names
      Page<String> logNames = logging.listLogs();
      while (logNames != null) {
        for (String logName : logNames.iterateAll()) {
          System.out.println(logName);
        }
        logNames = logNames.getNextPage();
      }
    }
  }
}

Node.js

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

// Imports the Google Cloud client library
const {Logging} = require('@google-cloud/logging');

// Creates a client
const logging = new Logging();

async function printLogNames() {
  const [logs] = await logging.getLogs();
  console.log('Logs:');
  logs.forEach(log => {
    console.log(log.name);
  });
}
printLogNames();

What's next

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