Package-level log configuration helps you control how much detail your app shows in logs for specific parts. It keeps logs clear and useful.
Package-level log configuration in Spring Boot
logging.level.<package-name>=<log-level>
Replace <package-name> with the Java package you want to configure, like com.example.service.
Replace <log-level> with levels like TRACE, DEBUG, INFO, WARN, ERROR.
com.example.service package.logging.level.com.example.service=DEBUG
logging.level.org.springframework.web=INFO
logging.level.root=WARN
This example sets DEBUG logs for the controller package and ERROR logs for the repository package. When the controller method runs, debug and info logs appear. When the repository method runs, only error logs appear.
application.properties logging.level.com.example.controller=DEBUG logging.level.com.example.repository=ERROR // Sample Spring Boot Controller class package com.example.controller; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { private static final Logger logger = LoggerFactory.getLogger(HelloController.class); @GetMapping("/hello") public String sayHello() { logger.debug("Debug: Entering sayHello method"); logger.info("Info: Returning greeting message"); return "Hello, World!"; } } // Sample Spring Boot Repository class package com.example.repository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Repository; @Repository public class DataRepository { private static final Logger logger = LoggerFactory.getLogger(DataRepository.class); public void fetchData() { logger.error("Error: Data fetch failed"); logger.info("Info: This info will not show because level is ERROR"); } }
Package names are case-sensitive and must match your Java package structure exactly.
Use root to set a default log level for all packages.
Changing log levels at runtime may require restarting your Spring Boot app.
Package-level log configuration controls log detail per Java package.
Set it in application.properties using logging.level.<package>=<level>.
This helps focus on important logs and reduce noise.
Practice
logging.level.<package>=<level> in Spring Boot's application.properties?Solution
Step 1: Understand the configuration key
The keylogging.level.<package>is used to specify logging levels for Java packages in Spring Boot.Step 2: Identify the purpose of this setting
This setting controls how detailed the logs are for that package, helping to focus on important logs and reduce noise.Final Answer:
To control the logging detail for a specific Java package -> Option AQuick Check:
Package-level log control = A [OK]
- Confusing logging level with server or database settings
- Trying to set logging level without specifying a package
- Using incorrect property keys like logging.package.level
com.example.service in application.properties?Solution
Step 1: Recall the correct property format
The correct format islogging.level.<package>=<level>, so the package name comes immediately afterlogging.level..Step 2: Match the option to the format
logging.level.com.example.service=DEBUG matches this format exactly:logging.level.com.example.service=DEBUG.Final Answer:
logging.level.com.example.service=DEBUG -> Option DQuick Check:
Correct syntax = B [OK]
- Adding extra '=' signs in the property
- Swapping order of package and level
- Using 'log.level' instead of 'logging.level'
application.properties settings:logging.level.com.example=INFOlogging.level.com.example.service=DEBUGWhat will be the log level for classes in
com.example.service package?Solution
Step 1: Understand package-level log hierarchy
More specific package settings override broader ones. Here,com.example.serviceis more specific thancom.example.Step 2: Determine effective log level
Thecom.example.servicepackage is set to DEBUG, which overrides the INFO level set forcom.example.Final Answer:
DEBUG -> Option BQuick Check:
Specific package level overrides general = C [OK]
- Assuming parent package level applies to all subpackages
- Ignoring more specific package settings
- Confusing INFO and DEBUG levels
logging.level.com.example=TRACE in application.properties but still see only INFO logs from com.example classes. What is the most likely cause?Solution
Step 1: Verify if TRACE is supported
TRACE is a valid log level in Spring Boot, so this is not the issue.Step 2: Consider configuration overrides
If logs show INFO instead of TRACE, likely another config (like environment variables or YAML) overrides the level to INFO.Final Answer:
Another configuration overrides the log level to INFO -> Option CQuick Check:
Config override causes unexpected log level = D [OK]
- Assuming TRACE is unsupported
- Not checking for typos in package name
- Ignoring global logging settings
ERROR level for com.example.repository but keep DEBUG for com.example.service. Which application.properties configuration achieves this?Solution
Step 1: Set ERROR level specifically for repository package
Uselogging.level.com.example.repository=ERRORto reduce noise from repository logs.Step 2: Set DEBUG level specifically for service package
Uselogging.level.com.example.service=DEBUGto keep detailed logs for service package.Step 3: Combine both settings correctly
logging.level.com.example.repository=ERROR logging.level.com.example.service=DEBUG correctly sets both packages with their respective levels inapplication.properties.Final Answer:
logging.level.com.example.repository=ERROR logging.level.com.example.service=DEBUG -> Option AQuick Check:
Separate package levels set correctly = A [OK]
- Setting parent package level instead of specific packages
- Swapping log levels between packages
- Using incorrect property keys or syntax
Ready to prove it?
Pass the test and this pattern moves unknown
