GCP和Spring登录.严重程度永远是信息 [英] GCP and Spring logback. Severity is always info

查看:119
本文介绍了GCP和Spring登录.严重程度永远是信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将错误记录到stackdriver时,即使使用log.error或log.warn等,每条消息都将记录为INFO,但是有效负载是正确的.

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.

我希望能够按严重性过滤并收到有关错误的电子邮件.

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

我正在使用Spring Boot和Logback.该应用程序已部署在GCP的Kubernetes集群上.

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

这是我的logback-spring.xml

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>

这是在Maven中添加的dep

And here is the dep added in Maven

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

Spring Boot版本:2.1.3.RELEASE
Spring Cloud版本:Greenwich.RELEASE

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

此配置有什么问题?还有其他解决方案吗?

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

刚刚意识到上面的STACKDRIVER附加器不是一个记录到Stackdriver的日志,但是STDOUT足够了(也许因为它是Kubernetes集群?),但问题仍然存在

推荐答案

对于任何写入容器stdout的日志,Kubernetes的Stackdriver日志记录代理配置默认为INFO,对于写入stderr的日志则默认为ERROR.如果您希望对严重性进行更细粒度的控制,可以将Spring配置为以单行JSON记录(例如,通过JsonLayout 1 ),并让日志记录代理从JSON对象中获取严重性. (请参见 https://cloud.google.com/logging/docs/agent/configuration#process-payload ).

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).

1 默认情况下,JsonLayout将使用级别"作为日志级别,而Stackdriver日志代理addCustomDataToJsonMap.

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

另请参见 GKE& Stackdriver:Java Logback日志记录格式?

这篇关于GCP和Spring登录.严重程度永远是信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆