一尘不染

在Spring框架中启用日志记录

spring-boot

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

我知道如何在纯Spring MVC项目中启用日志记录,我在这里尝试过相同的操作,但无法正常工作。

有人可以帮我吗

我的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等的3rd party jars。


阅读 306

收藏
2020-05-30

共1个答案

一尘不染

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

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

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

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

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

输出到temp_folder / file

logging.file=${java.io.tmpdir}/application.log
2020-05-30