GCP and Spring logback. Severity is always info

2019-08-30 01:28发布

When logging errors to stackdriver, every message is logged as INFO, even when using log.error or log.warn, etc., but the payload is correct.

enter image description here

I'd like to be able to filter by severity and get email on error.

I'm using Spring Boot and Logback. The app has been deployed on a Kubernetes Cluster on GCP.

Here is my logback-spring.xml

<configuration>
    <include resource="org/springframework/cloud/gcp/autoconfigure/logging/logback-appender.xml" />

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are assigned the type
             ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
        <encoder>
            <pattern>%d{HH:mm:ss, UTC} %-5level %logger{35} - %msg %n</pattern>
        </encoder>
    </appender>

    <springProfile name="prod,qa">

        <root level="WARN">
            <appender-ref ref="STACKDRIVER" />
        </root>
    </springProfile>

</configuration>

And here is the dep added in Maven

<dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-gcp-starter-logging</artifactId>
</dependency>

Spring Boot version: 2.1.3.RELEASE
Spring Cloud version: Greenwich.RELEASE

What is wrong with this config? Is there any other solution?

EDIT: Just realized that the STACKDRIVER appender above is not the one logging to Stackdriver, but STDOUT is enough (maybe bc it's a Kubernetes cluster?), but the issue persists

1条回答
虎瘦雄心在
2楼-- · 2019-08-30 02:12

The Stackdriver logging agent configuration for Kubernetes defaults to INFO for any logs written to the container's stdout and ERROR for logs written to stderr. If you want finer-grained control over severity, you can configure Spring to log as single-line JSON (e.g., via JsonLayout1) and let the logging agent pick up the severity from the JSON object (see https://cloud.google.com/logging/docs/agent/configuration#process-payload).

1By default, JsonLayout will use "level" for the log level, while the Stackdriver logging agent recognizes "severity", so you may have to override addCustomDataToJsonMap.

See also GKE & Stackdriver: Java logback logging format?

查看更多
登录 后发表回答