google cloud kubernetes spring引导组请求日志不起作用

i1icjdpr  于 2021-07-26  发布在  Java
关注(0)|答案(0)|浏览(204)

我在google云k8s中部署了一个spring-boot微服务,我试图通过一个http请求对日志进行分组,但是没有工作所有日志都是独立的,
我在用 gradle , spring-boot , spring-cloud-gcp-starter-logging , org.springframework.cloud:spring-cloud-starter-sleuth 这是我的 build.gradle ```
plugins {
id "jacoco"
id 'net.ltgt.apt' version '0.20'
id 'org.springframework.boot' version '2.4.1'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id "org.sonarqube" version "3.0"
id 'java'
}

apply plugin: 'net.ltgt.apt-idea'
apply plugin: "io.spring.dependency-management"

sourceCompatibility = '11'

bootJar {
launchScript()
}

ext {
springBootVersion='2.4.1'
mapstructVersion='1.4.1.Final'
lombokVersion = '1.18.12'
reactorVersion = '3.4.1'
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
}

dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:2020.0.1"
}
}

dependencies {
implementation "org.springframework.boot:spring-boot-starter-web:${springBootVersion}"
implementation "org.mapstruct:mapstruct:${mapstructVersion}", "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}", "org.mapstruct:mapstruct-processor:${mapstructVersion}"
implementation "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}"
implementation "com.h2database:h2"
implementation group: 'com.auth0', name: 'java-jwt', version: '3.13.0'

//TRACE
compile "org.springframework.cloud:spring-cloud-starter-sleuth"

//LOGS
implementation group: 'org.springframework.cloud', name: 'spring-cloud-gcp-starter-logging', version: '1.2.8.RELEASE'

testImplementation "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
testAnnotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"

}

jacocoTestReport {
reports {
xml.enabled true
}
}

test {
useJUnitPlatform()
finalizedBy jacocoTestReport // report is always generated after tests run
}

jacocoTestReport {
dependsOn test // tests are required to run before generating the report
}

sonarqube {
properties {
property 'sonar.projectName', 'my-project'
property "sonar.exclusions", "/entities/*.java,/ServletInitializer.java,**/Application.java"
}
}

tasks['sonarqube'].dependsOn test

这是我的 `logback.xml` ```
<configuration>

    <property name="projectId" value="my-project"/>

    <appender name="CONSOLE_JSON" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="org.springframework.cloud.gcp.logging.StackdriverJsonLayout">
                <projectId>${projectId}</projectId>
            </layout>
        </encoder>
    </appender>

    <root level="INFO">
        <appender-ref ref="CONSOLE_JSON" />
    </root>
</configuration>

  private static final Logger logger = LoggerFactory.getLogger(MyControllerController.class);

    @GetMapping("/test")
    public String pruebaLogs() {
        logger.info("Get all data with {} and {}", 2, 32);
        logger.info("Get all data with type {}", 3333);

        logger.error("An error");
        logger.warn("An warning");
        logger.debug("An debug");

        return "log";
    }

我试图创建一个自定义过滤器来添加 x-cloud-trace-context 但如果我用 Sleuth 所有日志应自动分组

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题