com.google.cloud.logging.Logging.EntryListOption Java Examples

The following examples show how to use com.google.cloud.logging.Logging.EntryListOption. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ListLogs.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
/** Expects an existing Stackdriver log name as an argument. */
public static void main(String... args) throws Exception {
  // [START logging_list_log_entries]
  // Instantiates a client
  LoggingOptions options = LoggingOptions.getDefaultInstance();

  String logName = args[0];

  try (Logging logging = options.getService()) {

    String logFilter = "logName=projects/" + options.getProjectId() + "/logs/" + logName;

    // List all log entries
    Page<LogEntry> entries = logging.listLogEntries(
        EntryListOption.filter(logFilter));
    do {
      for (LogEntry logEntry : entries.iterateAll()) {
        System.out.println(logEntry);
      }
      entries = entries.getNextPage();
    } while (entries != null);

  }
  // [END logging_list_log_entries]
}
 
Example #2
Source File: LoggingSnippets.java    From google-cloud-java with Apache License 2.0 6 votes vote down vote up
/** Example of asynchronously listing log entries for a specific log. */
// [TARGET listLogEntriesAsync(EntryListOption...)]
// [VARIABLE "logName=projects/my_project_id/logs/my_log_name"]
public Page<LogEntry> listLogEntriesAsync(String filter)
    throws ExecutionException, InterruptedException {
  // [START listLogEntriesAsync]
  Future<AsyncPage<LogEntry>> future =
      logging.listLogEntriesAsync(EntryListOption.filter(filter));
  // ...
  AsyncPage<LogEntry> entries = future.get();
  for (LogEntry entry : entries.iterateAll()) {
    // do something with the entry
  }
  // [END listLogEntriesAsync]
  return entries;
}
 
Example #3
Source File: LoggingSnippets.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
/** Example of listing log entries for a specific log. */
// [TARGET listLogEntries(EntryListOption...)]
// [VARIABLE "logName=projects/my_project_id/logs/my_log_name"]
public Page<LogEntry> listLogEntries(String filter) {
  // [START logging_list_log_entries]
  Page<LogEntry> entries = logging.listLogEntries(EntryListOption.filter(filter));
  for (LogEntry entry : entries.iterateAll()) {
    // do something with the entry
  }
  // [END logging_list_log_entries]
  return entries;
}
 
Example #4
Source File: WriteAndListLogEntries.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
public static void main(String... args) throws Exception {
  // Create a service object
  // Credentials are inferred from the environment
  LoggingOptions options = LoggingOptions.getDefaultInstance();
  try (Logging logging = options.getService()) {

    // Create a log entry
    LogEntry firstEntry =
        LogEntry.newBuilder(StringPayload.of("message"))
            .setLogName("test-log")
            .setResource(
                MonitoredResource.newBuilder("global")
                    .addLabel("project_id", options.getProjectId())
                    .build())
            .build();
    logging.write(Collections.singleton(firstEntry));

    // List log entries
    Page<LogEntry> entries =
        logging.listLogEntries(
            EntryListOption.filter(
                "logName=projects/" + options.getProjectId() + "/logs/test-log"));
    for (LogEntry logEntry : entries.iterateAll()) {
      System.out.println(logEntry);
    }
  }
}
 
Example #5
Source File: LoggingExample.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Logging logging, String filter) {
  Page<LogEntry> entryPage;
  if (filter == null) {
    entryPage = logging.listLogEntries();
  } else {
    entryPage = logging.listLogEntries(EntryListOption.filter(filter));
  }
  for (LogEntry entry : entryPage.iterateAll()) {
    System.out.println(entry);
  }
}