本文介绍了在Spring Boot应用程序中启用Spring框架的日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Spring Boot创建了一个简单的Web应用程序,我想为springframework软件包启用调试日志.

I have created simple web-app using spring boot and I want to enable debug logs for springframework package.

我知道如何在纯Spring MVC项目中启用日志记录,我在这里尝试过相同的操作,但是它不起作用.

I know the how to enable logging in plain spring mvc project, I have tried the same here but it won't works.

有人可以在这里帮我吗

我的pom.xml是

<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>StartUp</groupId>
    <artifactId>StartUp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

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

    </parent>

    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>

        <!-- This is a web application -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- Tomcat embedded container -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- JSTL for JSP -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

        <!-- Need this to compile JSP -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Need this to compile JSP, tomcat-embed-jasper version is not
            working, no idea why -->
        <dependency>
            <groupId>org.eclipse.jdt.core.compiler</groupId>
            <artifactId>ecj</artifactId>
            <version>4.6.1</version>
            <scope>provided</scope>
        </dependency>

        <!-- Optional, test for static content, bootstrap CSS -->
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>3.3.7</version>
        </dependency>


    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jul-to-slf4j</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>log4j-over-slf4j</artifactId>
    </dependency>

    </dependencies>

    <build>
        <plugins>
            <!-- Package as an executable jar/war -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

我最感兴趣的是打印记录诸如springFramework,hibernate等之类的第三方聚会

I mostly interested to print 3rd party jars logging like springFramework, hibernate etc.

推荐答案

默认情况下,Spring Boot启动程序包中包含SLF4j日志记录

By default, the SLF4j Logging is included in the Spring Boot starter package

要启用日志记录,必须在配置属性文件(application.properties/application.yaml)中定义日志记录级别.

To enable logging, you have to define logging level in your configuration properties file(application.properties/application.yaml).

例如:要查看控制台中的日志,请设置以下属性 logging.level.org.springframework.web = ERRORlogging.level.com =调试

For example: To see the logs in console set the following properties logging.level.org.springframework.web=ERROR logging.level.com=DEBUG

要输出日志文件,请设置以下属性

To output the logs in file, set the following properties

logging.level.org.springframework.web=ERROR
logging.level.com=DEBUG

输出到temp_folder/文件

logging.file=${java.io.tmpdir}/application.log

这篇关于在Spring Boot应用程序中启用Spring框架的日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 20:37