@@ -18,6 +18,7 @@ This client supports the following Google Cloud Platform services:
1818- [ Google Cloud Compute] (#google-cloud-compute-alpha) (Alpha)
1919- [ Google Cloud Datastore] (#google-cloud-datastore)
2020- [ Google Cloud DNS] (#google-cloud-dns-alpha) (Alpha)
21+ - [ Stackdriver Logging] (#stackdriver-logging-alpha) (Alpha - Not working on App Engine Standard)
2122- [ Google Cloud Pub/Sub] (#google-cloud-pubsub-alpha) (Alpha - Not working on App Engine Standard)
2223- [ Google Cloud Resource Manager] (#google-cloud-resource-manager-alpha) (Alpha)
2324- [ Google Cloud Storage] (#google-cloud-storage)
@@ -371,6 +372,75 @@ ChangeRequestInfo changeRequest = changeBuilder.build();
371372zone.applyChangeRequest(changeRequest);
372373` ` `
373374
375+ Stackdriver Logging (Alpha)
376+ ----------------------
377+ - [API Documentation][logging-api]
378+ - [Official Documentation][stackdriver-logging-docs]
379+
380+ * Follow the [activation instructions][stackdriver-logging-activation] to use the Stackdriver Logging
381+ API with your project.*
382+
383+ # ### Preview
384+
385+ Here are two code snippets showing simple usage examples from within Compute Engine/App Engine
386+ Flexible. Note that you must [supply credentials](# authentication) and a project ID if running this
387+ snippet elsewhere.
388+
389+ The first snippet shows how to write and list log entries. Complete source code can be found on
390+ [WriteAndListLogEntries.java](./gcloud-java-examples/src/main/java/com/google/cloud/examples/logging/snippets/WriteAndListLogEntries.java).
391+
392+ ` ` ` java
393+ import com.google.cloud.MonitoredResource;
394+ import com.google.cloud.Page;
395+ import com.google.cloud.logging.LogEntry;
396+ import com.google.cloud.logging.Logging;
397+ import com.google.cloud.logging.Logging.EntryListOption;
398+ import com.google.cloud.logging.LoggingOptions;
399+ import com.google.cloud.logging.Payload.StringPayload;
400+
401+ import java.util.Collections;
402+ import java.util.Iterator;
403+
404+ LoggingOptions options = LoggingOptions.defaultInstance ();
405+ try(Logging logging = options.service ()) {
406+
407+ LogEntry firstEntry = LogEntry.builder(StringPayload.of(" message" ))
408+ .logName(" test-log" )
409+ .resource(MonitoredResource.builder(" global" )
410+ .addLabel(" project_id" , options.projectId ())
411+ .build ())
412+ .build ();
413+ logging.write(Collections.singleton(firstEntry));
414+
415+ Page< LogEntry> entries = logging.listLogEntries(
416+ EntryListOption.filter(" logName=projects/" + options.projectId () + " /logs/test-log" ));
417+ Iterator< LogEntry> entryIterator = entries.iterateAll ();
418+ while (entryIterator.hasNext()) {
419+ System.out.println(entryIterator.next ());
420+ }
421+ }
422+ ` ` `
423+
424+ The second snippet shows how to use a ` java.util.logging.Logger` to write log entries to Stackdriver
425+ Logging. The snippet installs a Stackdriver Logging handler using
426+ ` LoggingHandler.addHandler(Logger, LoggingHandler)` . Notice that this could also be done through the
427+ ` logging.properties` file, adding the following line:
428+ ` ` `
429+ com.google.cloud.examples.logging.snippets.AddLoggingHandler.handlers=com.google.cloud.logging.LoggingHandler
430+ ` ` `
431+ The complete code can be found on
432+ [AddLoggingHandler.java](./gcloud-java-examples/src/main/java/com/google/cloud/examples/logging/snippets/AddLoggingHandler.java).
433+
434+ ` ` ` java
435+ import com.google.cloud.logging.LoggingHandler;
436+
437+ import java.util.logging.Logger;
438+
439+ Logger logger = Logger.getLogger(AddLoggingHandler.class.getName ());
440+ LoggingHandler.addHandler(logger, new LoggingHandler ());
441+ logger.warning(" test warning" );
442+ ` ` `
443+
374444Google Cloud Pub/Sub (Alpha)
375445----------------------
376446
@@ -554,6 +624,10 @@ Apache 2.0 - See [LICENSE] for more information.
554624[cloud-dns-docs]: https://cloud.google.com/dns/docs
555625[cloud-dns-activation]: https://console.cloud.google.com/start/api? id=dns
556626
627+ [logging-api]: http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html? com/google/cloud/logging/package-summary.html
628+ [stackdriver-logging-docs]: https://cloud.google.com/logging/docs
629+ [stackdriver-logging-activation]: https://console.cloud.google.com/start/api? id=logging
630+
557631[pubsub-api]: http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html? com/google/cloud/pubsub/package-summary.html
558632[cloud-pubsub]: https://cloud.google.com/pubsub/
559633[cloud-pubsub-docs]: https://cloud.google.com/pubsub/docs
0 commit comments