0
0
Spring Bootframework~30 mins

Package-level log configuration in Spring Boot - Mini Project: Build & Apply

Choose your learning style9 modes available
Package-level log configuration in Spring Boot
📖 Scenario: You are building a Spring Boot application that has multiple packages. You want to control the logging level separately for each package to help with debugging and monitoring.
🎯 Goal: Configure logging levels at the package level in a Spring Boot application using application.properties file.
📋 What You'll Learn
Create a Spring Boot project with at least two packages: com.example.service and com.example.controller
Set the logging level for com.example.service to DEBUG
Set the logging level for com.example.controller to INFO
Verify that the logging configuration is correctly applied
💡 Why This Matters
🌍 Real World
In real projects, controlling logging levels per package helps developers focus on relevant logs and reduces noise during debugging and monitoring.
💼 Career
Understanding package-level logging configuration is essential for backend developers working with Spring Boot to maintain and troubleshoot applications efficiently.
Progress0 / 4 steps
1
Create packages in the Spring Boot project
Create two packages in your Spring Boot project: com.example.service and com.example.controller. You do not need to add any classes yet.
Spring Boot
Need a hint?

In your IDE or project structure, create the two packages exactly as com.example.service and com.example.controller.

2
Add logging level configuration in application.properties
In the src/main/resources/application.properties file, add two lines to set the logging level for com.example.service to DEBUG and for com.example.controller to INFO.
Spring Boot
Need a hint?

Open application.properties and add these exact lines:

logging.level.com.example.service=DEBUG
logging.level.com.example.controller=INFO
3
Add simple classes to each package with logging
Create a class ServiceClass in com.example.service and a class ControllerClass in com.example.controller. In each class, add a logger and a method that logs a message at the DEBUG level for ServiceClass and at the INFO level for ControllerClass.
Spring Boot
Need a hint?

Create two classes with the exact names and add logging using LoggerFactory.getLogger. Use logger.debug in ServiceClass and logger.info in ControllerClass.

4
Complete the Spring Boot application with main class and run
Add the main Spring Boot application class Application in com.example package. In the main method, create instances of ServiceClass and ControllerClass and call their logging methods. This completes the package-level log configuration setup.
Spring Boot
Need a hint?

Create a Application class annotated with @SpringBootApplication. In main, run the app and call the logging methods on instances of ServiceClass and ControllerClass.