我在应用程序中使用Spring MVC Java,日志是GCP上托管的应用程序的输出。 logback.xml
在领事中定义。我在应用程序的输出中得到重复的日志
[][]2020-02-09T19:14:43,675+07:00 WARN
c.g.s.b.s.spring.SessionInterceptor - Invalid session, let's create new session
[][]2020-02-09T19:14:43,675+07:00 WARN
c.g.s.b.s.spring.SessionInterceptor - Invalid session, let's create new session
10.0.27.1 - - [09/Feb/2020:19:14:43 +0700] "GET /mobile-api/sys-info/healthcheck HTTP/1.1" 200 83 0.092
[][]2020-02-09T19:14:53,668+07:00 WARN
c.g.s.b.s.spring.SessionInterceptor - Invalid session, let's create new session
[][]2020-02-09T19:14:53,668+07:00 WARN
c.g.s.b.s.spring.SessionInterceptor - Invalid session, let's create new session
10.0.27.1 - - [09/Feb/2020:19:14:53 +0700] "GET /mobile-api/sys-info/healthcheck HTTP/1.1" 200 83 0.083
[][]2020-02-09T19:15:03,656+07:00 WARN
c.g.s.b.s.spring.SessionInterceptor - Invalid session, let's create new session
[][]2020-02-09T19:15:03,656+07:00 WARN
c.g.s.b.s.spring.SessionInterceptor - Invalid session, let's create new session
10.0.27.1 - - [09/Feb/2020:19:15:03 +0700] "GET /mobile-api/sys-info/healthcheck HTTP/1.1" 200 83 0.088
[][]2020-02-09T19:15:13,661+07:00 WARN
c.g.s.b.s.spring.SessionInterceptor - Invalid session, let's create new session
[][]2020-02-09T19:15:13,661+07:00 WARN
c.g.s.b.s.spring.SessionInterceptor - Invalid session, let's create new session
这是我的配置文件:logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration scanPeriod="1 minutes" scan="true">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%X{key}][%X{user}]%date{"yyyy-MM-dd'T'HH:mm:ss,SSSXXX", Asia/Jakarta} %-5level
%logger{35} - %replace(%msg){'\n', ' '}%nopex%n
</pattern>
</encoder>
</appender>
<root level="warn">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
答案 0 :(得分:0)
Spring官方网页中介绍了在GCP中使用Java Spring进行登录。在11. Stackdriver Logging Support中。您需要添加页面中提到的相应依赖项,并将logback.xml更改为:
<configuration>
<include resource="org/springframework/cloud/gcp/logging/logback-appender.xml" />
<root level="INFO">
<appender-ref ref="STACKDRIVER" />
</root>
</configuration>