Spring Boot App Engine日志格式不正确 [英] Spring boot app engine logs not properly formatted

查看:99
本文介绍了Spring Boot App Engine日志格式不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在appengine上部署了spring boot 2应用程序,并且运行良好.

I've deployed a spring boot 2 application on appengine and its doing great.

唯一的问题是标准日志记录机制与gcp日志记录系统发生冲突.我得到的是数百条信息日志,即使出现异常或警告也是如此.

The only thing is that the standard logging mechanism clashes with the gcp logging system. What I get are hundred of info logs, even when there's an exception thrown or a warning.

我认为问题在于日志确实很长,并且以一些不必要的数据开头.

I think the problem is that the logs are really long and starts with some unnecessary data.

在我的配置中,我使用lombok + Slf4j登录我的应用程序,并且由于我已经安装了spring-boot-starter-web,因此我认为默认情况下启用了logback.

In my configuration I use lombok+Slf4j to log inside my application, and I think logback is enabled by default since I've spring-boot-starter-web.

我的pom具有以下依赖性:

my pom has these depencencies:

   <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-gcp-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-gcp-starter-data-datastore</artifactId>
        </dependency>

        <!--Standard dep-->

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-api-1.0-sdk</artifactId>
            <version>${appengine.target.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.api-client</groupId>
            <artifactId>google-api-client-appengine</artifactId>
            <version>1.29.2</version>
        </dependency>

        <!--Provided-->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

        <!--Test related-->

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

并在资源文件夹中,有

and in the resource folder I've the logging.properties file as suggested in the spring boot page for app engine (avoid stack overflow errors during the startup)

唯一的区别是,如果我排除jul-to-slf4j,则在控制台中将看不到任何日志.

With the only difference that if I exclude jul-to-slf4j, I won't see any log in the console.

任何其他关于Logback/Spring Boot的专家都可以向我指出正确的方向吗?

Anyone more expert on logback / spring boot can point me in the right direction ?

推荐答案

最后,我没有找到使用Spring Boot在App Engine标准中通过控制台打印机显示日志的正确方法.但是,通过使用stackdriver api,日志确实更漂亮.

In the end I didn't find the proper way to display the logs by console printer in app engine standard with spring boot. However, by using the stackdriver api the logs are indeed prettier.

我所做的包括:

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

在logback-spring.xml中

And in logback-spring.xml

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

<springProfile name="local">
    <root level="INFO">
        <appender-ref ref="CONSOLE"/>
    </root>
</springProfile>

<springProfile name="!local">
    <root level="INFO">
        <appender-ref ref="STACKDRIVER"/>
    </root>
</springProfile>

但是,主请求日志级别未显示最高日志级别(而是任何日志值"),这使得过滤更加困难. 另一方面,由于内部日志已设置了适当的级别,因此错误报告也可以工作.

However, the main request log level don't show the highest log level (but the "any log value") making filtering harder. On the other end, error reporting works because the inner logs have the proper level set.

这篇关于Spring Boot App Engine日志格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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