当前位置: 首页 > 知识库问答 >
问题:

添加依赖项后,spring cloud sleuth不会在日志中显示任何信息

子车海
2023-03-14

我已经将sleuth依赖项添加到我的Spring boot项目中。虽然存在依赖项,但在日志中看不到任何跟踪信息。没有编译或运行时错误。

 <?xml version="1.0" encoding="UTF-8"?>
   <project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
    http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>TestProject</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>TestProject</name>
    <description>Test Project.</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath />
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.RC2</spring-cloud.version>
    </properties>

    <repositories>
        <repository>
            <id>ccp-master</id>
            <url>https://maven.teamccp.com/content/groups/master</url>
        </repository>

        <repository>
            <id>spring-release</id>
            <url>http://repo.spring.io/libs-release</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>

        <repository>
            <id>spring-milestone</id>
            <url>http://repo.spring.io/libs-milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>

        <repository>
            <id>spring-snapshot</id>
            <url>http://repo.spring.io/libs-snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

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

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sleuth</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cache</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sleuth</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>com.vaadin.external.google</groupId>
                    <artifactId>android-json</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- for jackson -->
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-xml</artifactId>
        </dependency>

        <!-- Swagger Dependencies -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.2.2</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.2.2</version>
            <scope>compile</scope>
        </dependency>

        <!-- Hazelcast Dependencies -->
        <dependency>
            <groupId>javax.cache</groupId>
            <artifactId>cache-api</artifactId>
            <version>1.0.0</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>com.hazelcast</groupId>
            <artifactId>hazelcast-all</artifactId>
            <version>3.6.4</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>

        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.1</version>
        </dependency>

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>1.19.4</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.1</version>
        </dependency>

        <dependency>
            <groupId>com.comcast.sat</groupId>
            <artifactId>sat-core</artifactId>
            <version>1.3</version>
        </dependency>

        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20160810</version>
        </dependency>

        <dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>1.14</version>
        </dependency>

        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcpkix-jdk15on</artifactId>
            <version>1.48</version>
        </dependency>

        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk15on</artifactId>
            <version>1.60</version>
        </dependency>

    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

以下是控制器代码:

@RestController
@RequestMapping("/api/v1/device/")
public class TestProjectController {

private Logger logger = 
LoggerFactory.getLogger(this.getClass());

@Autowired
private TestProjectService tpService;

@RequestMapping(value = "/boottest", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<? extends Object> acquireLDAP(@RequestBody TestProjRequestModel onboardRequest,
        @RequestHeader HttpHeaders headers) {
    String traceId = UUID.randomUUID().toString();
    logger.info("traceId=" + traceId + "request=/boottest msg=Request to Onboard requestBody=" + onboardRequest);
    JsonEntity entity = new JsonEntity();
    try {
        ResponseEntity<? extends Object> responseEntity = new ResponseEntity<String>("test", HttpStatus.OK);
        HttpHeaders respHeaders =  responseEntity.getHeaders();
        for (Map.Entry<String, List<String>> entry : respHeaders.entrySet()) {
            String headerName = entry.getKey();
            for (String headerValue : entry.getValue()) {
                logger.info("Header Name::  " + headerName);
                logger.info("Header Val::  " + headerValue);
            }
        }
        return responseEntity;

我认为是

   2019-01-08 12:22:01,400 INFO  (c.c.l.o.c.TestProjectController:52) | 

请建议可以做些什么来按预期查看日志?预期的日志类似于

2016-06-05 17:12:45.404  INFO [my-service3-id,73b62c0f90d11e06,73b62c0f90d11e06,false] 

共有1个答案

孙佑运
2023-03-14

您需要在日志配置中添加MDC变量,如%X{X-B3-TraceId:-}请参阅https://cloud.spring.io/spring-cloud-sleuth/single/spring-cloud-sleuth.html#_log_correlation

 类似资料:
  • 我在试着设置QAF。早些时候,当我设置框架时,我可以在控制台和输出日志文件中看到驱动程序日志。但现在我看不到他们了。我没有在日志文件配置或它的目录中做任何更改。有人能给我一些建议吗?

  • 我希望有人能帮忙。 在一台全新的windows机器上。在下载和运行最新版本的eclipse(indigo)之前,我已经下载并安装了java jdk。 3: 4:

  • 问题内容: 如何获取我拥有的jar文件并将其添加到Maven 2的依赖系统中?我将成为此依赖项的维护者,并且我的代码需要在类路径中使用此jar,以便对其进行编译。 问题答案: 您必须分两步执行此操作: 1.给您的JAR一个groupId,artifactId和版本,然后将其添加到您的存储库中。 如果您没有内部存储库,而只是试图将JAR添加到本地存储库,则可以使用任意groupId / artifa

  • 我使用的是Android studio版本 在项目级分级中: 模块级别等级: 当我导入它时,它发生错误 导入此时 xml错误 错误图片 在xml中添加此标记时发生错误 为此给出解决方案!!!

  • 我试图创建一个maven项目,并在以后添加Spring Boot依赖项,但我一直在maven插件上得到错误高亮显示。下面是截图:Maven Projects截图来自intellij

  • 从我读到的内容来看,我似乎需要一个pom.xml文件。也许我应该先以某种方式将maven添加到项目中?