Skip to content
Branch: master
Find file History


Spring Cloud GCP Logging Starter Example

This sample application demonstrates using the Spring Cloud GCP Logging Starter to store and group logs by trace ID, with the Google Stackdriver Logging API.

Setup & Configuration

  1. Create a Google Cloud Platform Project

  2. Have the Google Cloud SDK installed, initialized and logged in with application default credentials.

  3. Check that the Stackdriver Logging API is enabled.

Running the Example

Run the sample application from Maven:

$ mvn spring-boot:run

Then, issue a request containing the x-cloud-trace-context header to the localhost:8080/log endpoint and verify that a label appears in Stackdriver:

$ curl --header "x-cloud-trace-context: [Some-Trace-ID]" localhost:8080/log

To see the logged lines, navigate to the Logging section of the Cloud Console. Select the Global resource and look under the spring.log channel to see the logged text.

If your application is deployed to Google App Engine (GAE) or Google Kubernetes Engine (GKE), you will instead find the logs under the deployment’s resource in the Stackdriver UI under the spring.log channel. You can further narrow down the log by request by using the following filtering text that takes advantage of the trace ID label in each logged line. For example, if deployed to App Engine (by using mvn appengine:deploy in this sample) you can use the following to filter by the trace ID:


Expand the log entry labels and note that label is set to the same value for both log messages. The trace ID header x-cloud-trace-context is set automatically when deployed to App Engine.

When running on GAE or GKE, also remember to remove the CONSOLE appender, otherwise logs will appear on Cloud Logging in duplicate: once in the spring.log stream and once in the stdout stream.
You can’t perform that action at this time.