Spring Boot禁用Spring Batch信息级别日志记录

时间:2019-09-16 16:10:35

标签: spring-boot spring-batch

我有一个Spring Boot应用程序,它从Quartz Scheduler中定期运行一个Spring Batch作业。每次作业运行有关它的信息时,总是记录如下:

Sep 16, 2019 5:01:56 PM org.springframework.batch.core.launch.support.SimpleJobLauncher$1 run
INFO: Job: [SimpleJob: [name=testJob]] launched with the following parameters: [{jobRunTime=1568649716469}]
Sep 16, 2019 5:01:56 PM org.springframework.batch.core.job.SimpleStepHandler handleStep
INFO: Executing step: [publishRequests]
Sep 16, 2019 5:01:56 PM org.springframework.batch.core.launch.support.SimpleJobLauncher$1 run
INFO: Job: [SimpleJob: [name=testJob]] completed with the following parameters: [{jobRunTime=1568649716469}] and the following status: [COMPLETED]

如何防止这种情况被记录?我正在将slf4j与log4j2一起记录。我尝试将这行添加到我的日志记录属性文件中,以便仅记录错误消息,但这不起作用:

logging.level.org.springframework.batch=ERROR

我正在将Spring Boot 2.1.2与Spring Batch 4.1.1一起使用

这是我的日志文件中的依赖项:

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
                <version>${spring-boot.version}</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-logging</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-log4j2</artifactId>
                <version>${spring-boot.version}</version>
            </dependency>

            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${slf4j.version}</version>
            </dependency>

            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-jcl</artifactId>
                <version>${slf4j.version}</version>
                <exclusions>
                    <exclusion>
                        <groupId>commons-logging</groupId>
                        <artifactId>commons-logging</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

我在名为logging.properties的日志文件中使用以下属性:


    handlers= java.util.logging.FileHandler

    .level= INFO

    java.util.logging.FileHandler.pattern = myApp.log
    java.util.logging.FileHandler.limit = 10000000
    java.util.logging.FileHandler.count = 20
    java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter

    java.util.logging.ConsoleHandler.level = SEVERE
    java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter


    java.util.logging.SimpleFormatter.format=[%1$tc] %4$s %2$s: %5$s %n

    logging.level.org.springframework.batch=ERROR

2 个答案:

答案 0 :(得分:1)

默认情况下,它使用 logback

也许您的配置不考虑您的log4j2。

要修复此问题:创建一个 logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <logger name="org.springframework.batch" level="ERROR"/>
</configuration>

答案 1 :(得分:0)

我设法通过在我的logging.properties文件中将属性指定为

org.springframework.batch.level=ERROR