Google Cloud Services - Logging

This extension allows you to integrate your logs directly into Google Cloud Logging, including the ability to set resource labels and log record labels, include trace ID and to use structured logging.

You can integrate your logs into Cloud Logging via a standard logger of the object that you can inject in your code.

Bootstrapping the project

First, we need a new project. Create a new project with the following command (replace the version placeholder with the correct one):

mvn io.quarkus:quarkus-maven-plugin:<quarkusVersion>:create \
    -DprojectGroupId=org.acme \
    -DprojectArtifactId=firestore-quickstart \
cd firestore-quickstart

This command generates a Maven project, importing the Google Cloud Logging extension.

If you already have your Quarkus project configured, you can add the quarkus-google-cloud-logging extension to your project by running the following command in your project base directory:

./mvnw quarkus:add-extension -Dextensions="quarkus-google-cloud-logging"

This will add the following to your pom.xml:


How-to: Log

When configured, all that is needed is to log data as you wish. You can use JUL, jboss-logging or Slf4j, or even Google Cloud Logging directly. You can also inject the logger to use, for example:

package mypackage;

import javax.inject.Inject;

import org.jboss.logging.Logger;

public class LoggingResource {

    Logger logger;

    public String tryLog() {"Greeting the World");
        return "Hello World!";



Currently, the logging system uses a single Google Cloud Operations log and this is a mandatory configuration parameter.



If you want to disable the logging to Google Cloud you can do so:


This is useful for testing not to write to Google Operations during development:



This logging system can either use a standard text based format, Elastic Common Schema, or a completely custom schema.


Structured Logging

By setting the logging format to JSON this library will use the ECS format. As local record parameters and MDC values are not official part of the ECS specification, these default to parameters and mdc respectively, but this can be configured (see below).

  •[true|false] - Should stack traces be included? Default to true

  •[true|false] - Should log record parameters be included? Defaults to true

  • - This is the field name to use in ESC for parameters, defaults to parameters

  •[true|false] - Should the MDC values be included? Defaults to true

  • - This is the field name to use in ESC for MDC values, defaults to mdc

Resource type and labels

You can configure the resource type and the resource labels. This is used by Google Cloud Operations as dimensions when analysing logs. Please refer to the [Google Cloud documentation]( for the allowable resource types and their associated labels.

  • - The type string, defaults to generic_node

  •<string> - This is a string map with key/value pairs

Log record labels

You can configure default labels for each log record:

  •<string> - This is a string map with key/value pairs


In order to include trace and span ID in the log, you must bind a TraceInfoExtractor to the CDI context, e.g.:

package mypackage;

import javax.enterprise.context.ApplicationScoped;

import org.jboss.logmanager.ExtLogRecord;

import io.quarkiverse.googlecloudservices.logging.runtime.TraceInfo;
import io.quarkiverse.googlecloudservices.logging.runtime.TraceInfoExtractor;

public class TestTraceInfoExtractor implements TraceInfoExtractor {

    public TraceInfo extract(ExtLogRecord record) {
        return new TraceInfo(/* something, something */);

This will include the trace and span ID in the ESC log if they are not null. By default, this will also be set on the Google Cloud Operations log entry as a link to Google Cloud Operations tracing, but this is configurable:


Injecting GCP Logging

You can inject a instance directly. If you do so, the configuration for the project to use, still apply.

import java.time.Instant;
import java.util.List;


Logging gcpLogging;

public void log(String s) {