Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Black Friday 2026 – NPI EA – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

1. Overview

Logging is a critical component of any application, offering insights into its behavior and health. However, excessive logging can clutter output and obscure useful information, especially when verbose logs come from specific classes.

In this tutorial, we’ll explore how to disable logging from a specific class in Logback.

2. Why Disable Logging?

Disabling logging for specific classes can be beneficial in various scenarios:

  • Reducing Log Volume: reducing the volume of logs can help us focus on relevant information and reduce storage/processing costs.
  • Security: Some classes may log sensitive information inadvertently; silencing them can mitigate this risk.
  • Performance: Excessive logging can impact performance; disabling verbose loggers can help maintain optimal application performance.

3. Understanding Logback Configuration

Firstly, the Logback configuration is managed through an XML file, typically named logback.xml. This file defines loggers, appenders, and their formatting, allowing developers to control what gets logged and where.

A typical configuration includes one or more appenders and a root logger. Appenders define output destinations like the console or a file.

Here’s a simple example:

<configuration>
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg %n</pattern>
        </encoder>
    </appender>

    <root level="INFO">
        <appender-ref ref="console"/>
    </root>
</configuration>

This configuration directs INFO level (and higher) logs to the console, formatted with a date, thread name, log level, and log message.

4. Disabling Logging From a Specific Class

To disable logging from a specific class in Logback, we can define a logger for that class with the level set to OFF. This will silence all logging calls from the class.

4.1. Our VerboseClass

Let’s create our example VerboseClass to illustrate this tutorial:

public class VerboseClass {

    private static final Logger logger = LoggerFactory.getLogger(VerboseClass.class);

    public void process() {
        logger.info("Processing data in VerboseClass...");
    }

    public static void main(String[] args) {
        VerboseClass instance = new VerboseClass();
        instance.process();
        logger.info("Main method completed in VerboseClass");
    }
}

Then we can run it to see the log output:

17:49:53.901 [main] INFO  c.b.l.disableclass.VerboseClass - Processing data in VerboseClass... 
17:49:53.902 [main] INFO  c.b.l.disableclass.VerboseClass - Main method completed in VerboseClass 

4.2. Disabling Logging for VerboseClass

To disable its logs, add a logger entry in logback.xml:

<logger name="com.baeldung.logback.disableclass.VerboseClass" level="OFF"/>

Here’s how the logback.xml would look with this logger added:

<configuration>
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg %n</pattern>
        </encoder>
    </appender>

    <logger name="com.baeldung.logback.disableclass.VerboseClass" level="OFF"/>

    <root level="INFO">
        <appender-ref ref="console"/>
    </root>
</configuration>

With this configuration, VerboseClass will no longer output logs, while other classes will continue logging at the INFO level or above.

Finally, we can run this class again and see that no logs are displayed.

5. Conclusion

In summary, disabling logging from specific classes in Logback is a powerful feature that helps manage the signal-to-noise ratio in application logs. Setting the logging level to OFF for verbose or non-essential classes ensures that logs remain clear and meaningful. This also affects the overall performance and security of the application.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2026 – NPI EA – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW