javagoogle-cloud-platformlogbackgoogle-logging

Google LoggingAppender and stdout


For debugging/testing purposes, I would like Google's Logback LoggingAppender to write to STDOUT instead to connect to Google's Logging API. According to https://github.com/googleapis/java-logging-logback, this should be possible by using redirectToStdout.

My logback.xml:

    <appender name="CONSOLE" class="com.google.cloud.logging.logback.LoggingAppender">
        <redirectToStdout>true</redirectToStdout>
    </appender>
    <root>
        <level value="info" />
        <appender-ref ref="CONSOLE" />
    </root>

However, I get an error that no project was set. The error message:

14:48:36,515 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [com.google.cloud.logging.logback.LoggingAppender]
14:48:36,534 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [CONSOLE]
14:48:36,970 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@28:16 - RuntimeException in Action for tag [appender] java.lang.IllegalArgumentException: A project ID is required for this service but could not be determined from the builder or the environment.  Please set a project ID using the builder.
    at java.lang.IllegalArgumentException: A project ID is required for this service but could not be determined from the builder or the environment.  Please set a project ID using the builder.
    at  at com.google.common.base.Preconditions.checkArgument(Preconditions.java:142)
    ...

Although that should not be necessary according to the documentation cited above, I also tried setting logDestinationProjectId. Note, that doesn't make sense in my case, as I want to run this configuration on my local machine for debug/test purposes. Also, that produced a different error (although that should be ignored according to the documentation).

Any hints what I am missing? Is my use case even supported? If not, how do you test a configuration change for your LoggingAppender before deploying it to Google Cloud?


Solution

  • The linked github issue was accepted and confirmed by a contributor. You can work around by setting an arbitrary project ID, i.e. by setting logDestinationProjectId:

        <appender name="CONSOLE" class="com.google.cloud.logging.logback.LoggingAppender">
            <redirectToStdout>true</redirectToStdout>
            <logDestinationProjectId>TEST</logDestinationProjectId>
        </appender>
        <root>
            <level value="info" />
            <appender-ref ref="CONSOLE" />
        </root>