0

I have a Spring Boot application which runs a Spring Batch job at regular intervals from a Quartz Scheduler. Every time the job runs information about it is always logged as shown below:

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]

How can I prevent this from being logged? I am using slf4j with log4j2 for logging. I tried adding this line to my logging properties file so only error messages are logged but this did not work:

logging.level.org.springframework.batch=ERROR

I am using Spring Boot 2.1.2 with Spring Batch 4.1.1.

Here are the dependencies in my log file:

            <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>

I use the following properties for my logging in a log file called 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

5
  • you could try: log4j.logger.org.springframework.batch=error Commented Sep 16, 2019 at 16:29
  • share the pom.xml and log4j properties. Commented Sep 16, 2019 at 17:33
  • Without seeing your full properties / configuration, I can only assume one of a few things. You may be overridding this value somehow. Your configuration also may not be correct, so its not picking up any logging levels at all. Try also setting your root logging level to see if that makes an impact. Commented Sep 17, 2019 at 2:25
  • I have shared my pom.xml and logging properties file. Commented Sep 17, 2019 at 9:44
  • Thank you for updating with the information. My assumption is that two things are happening here. First, Spring Boot is defaulting to a logback configuration, which is why you are still getting logging. Second, you aren't telling Spring Boot where your logging.properties file is. Try adding an application property like this: logging.config=logging.properties Commented Sep 17, 2019 at 13:21

3 Answers 3

2

By default, it uses logback.

Maybe your configuration doesn't consider your log4j2.

To fix it: Create a 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>
Sign up to request clarification or add additional context in comments.

1 Comment

I'm not sure his intention is to switch logging frameworks to use logback. I believe he wants to use log4j and just fix the configuration.
0

I managed to get this working by specifying the property in my logging.properties file as

org.springframework.batch.level=ERROR

Comments

0

You need to adjust logging level like that: logging.level.root=ERROR

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.