google-cloud-logging overview (3.15.12)

A client for Cloud Logging - Real-time log management and analysis.

Here's a simple usage example for using google-cloud from Compute Engine/App Engine Flexible. This example shows how to write and list log entries. For the complete source code see

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

   LogEntry firstEntry = LogEntry.newBuilder(StringPayload.of("message"))
           .addLabel("project_id", options.getProjectId())

   Page<LogEntry> entries = logging.listLogEntries(
   EntryListOption.filter("logName=projects/" + options.getProjectId() + "/logs/test-log"));
   Iterator<LogEntry> entryIterator = entries.iterateAll();
   while (entryIterator.hasNext()) {

This second example shows how to use a java.util.logging.Logger to write log entries to Cloud Logging. The snippet installs a Cloud Logging handler using LoggingHandler.addHandler(Logger, LoggingHandler). Notice that this could also be done through the file, adding the following line:

For the complete source code see