Bird
Raised Fist0
Spring Bootframework~10 mins

Package-level log configuration in Spring Boot - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Package-level log configuration
Start Application
↓
Load application.properties
↓
Read logging.level.package=value
↓
Set log level for package
↓
Run application code
↓
Log messages filtered by package log level
↓
Output logs accordingly
Spring Boot reads the logging level set for a package from configuration and applies it to filter log messages during runtime.
Execution Sample
Spring Boot
logging.level.com.example.service=DEBUG

// In code:
logger.debug("Debug message");
logger.info("Info message");
Sets DEBUG level logging for 'com.example.service' package, so debug and higher messages appear.
Execution Table
StepActionPackage Log LevelLog MessageMessage LevelOutput?
1Start applicationdefault INFO--No output
2Load config: logging.level.com.example.service=DEBUGcom.example.service=DEBUG--No output
3Run code in com.example.serviceDEBUGDebug messageDEBUGYes
4Run code in com.example.serviceDEBUGInfo messageINFOYes
5Run code in com.example.otherINFO (default)Debug messageDEBUGNo
6Run code in com.example.otherINFO (default)Info messageINFOYes
7End of execution---Stop logging
💡 Application finishes running; logging stops.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 6Final
packageLogLevel['com.example.service']INFO (default)DEBUGDEBUGDEBUGDEBUG
packageLogLevel['com.example.other']INFO (default)INFO (default)INFO (default)INFO (default)INFO (default)
Key Moments - 2 Insights
Why does a DEBUG log message in 'com.example.other' package not appear?
Because 'com.example.other' uses the default INFO level, which filters out DEBUG messages as shown in execution_table row 5.
How does Spring Boot know which log level to apply to a package?
It reads the 'logging.level.<package>' property from configuration before running code, as seen in step 2 of the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the log level for 'com.example.service' after loading configuration?
AERROR
BINFO
CDEBUG
DWARN
💡 Hint
Check Step 2 in the execution_table where config is loaded.
At which step does a DEBUG message from 'com.example.other' get filtered out?
AStep 5
BStep 3
CStep 4
DStep 6
💡 Hint
Look at Step 5 in the execution_table for 'com.example.other' package.
If we set 'logging.level.com.example.other=DEBUG', what changes in the execution table?
AStep 6 output changes to No
BStep 5 output changes to Yes
CStep 3 output changes to No
DNo changes
💡 Hint
Refer to variable_tracker and Step 5 output behavior.
Concept Snapshot
Package-level log configuration in Spring Boot:
- Set log level per package in application.properties using 'logging.level.<package>=LEVEL'
- Levels: TRACE < DEBUG < INFO < WARN < ERROR
- Messages below set level are filtered out
- Helps focus logs on specific parts of app
- Default level is INFO if not set
Full Transcript
This visual execution shows how Spring Boot applies package-level log configuration. When the application starts, it loads the logging.level properties from application.properties. For example, setting logging.level.com.example.service=DEBUG means all debug and higher messages in that package will be logged. The execution table traces steps where messages are logged or filtered based on package log levels. Variables track the current log level per package. Key moments clarify why some messages appear or not. The quiz tests understanding of how configuration affects logging output.

Practice

(1/5)
1. What is the purpose of setting logging.level.<package>=<level> in Spring Boot's application.properties?
easy
A. To control the logging detail for a specific Java package
B. To define the database connection URL
C. To set the server port number
D. To configure the application's timezone

Solution

  1. Step 1: Understand the configuration key

    The key logging.level.<package> is used to specify logging levels for Java packages in Spring Boot.
  2. 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.
  3. Final Answer:

    To control the logging detail for a specific Java package -> Option A
  4. Quick Check:

    Package-level log control = A [OK]
Hint: Remember: logging.level.package sets log detail per package [OK]
Common Mistakes:
  • 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
2. Which of the following is the correct syntax to set the log level to DEBUG for the package com.example.service in application.properties?
easy
A. logging.level=com.example.service=DEBUG
B. log.level.com.example.service=DEBUG
C. logging.com.example.service.level=DEBUG
D. logging.level.com.example.service=DEBUG

Solution

  1. Step 1: Recall the correct property format

    The correct format is logging.level.<package>=<level>, so the package name comes immediately after logging.level..
  2. Step 2: Match the option to the format

    logging.level.com.example.service=DEBUG matches this format exactly: logging.level.com.example.service=DEBUG.
  3. Final Answer:

    logging.level.com.example.service=DEBUG -> Option D
  4. Quick Check:

    Correct syntax = B [OK]
Hint: Use logging.level.package=LEVEL exactly as shown [OK]
Common Mistakes:
  • Adding extra '=' signs in the property
  • Swapping order of package and level
  • Using 'log.level' instead of 'logging.level'
3. Given the following application.properties settings:
logging.level.com.example=INFO
logging.level.com.example.service=DEBUG
What will be the log level for classes in com.example.service package?
medium
A. INFO
B. DEBUG
C. ERROR
D. WARN

Solution

  1. Step 1: Understand package-level log hierarchy

    More specific package settings override broader ones. Here, com.example.service is more specific than com.example.
  2. Step 2: Determine effective log level

    The com.example.service package is set to DEBUG, which overrides the INFO level set for com.example.
  3. Final Answer:

    DEBUG -> Option B
  4. Quick Check:

    Specific package level overrides general = C [OK]
Hint: More specific package log level overrides parent package [OK]
Common Mistakes:
  • Assuming parent package level applies to all subpackages
  • Ignoring more specific package settings
  • Confusing INFO and DEBUG levels
4. You set logging.level.com.example=TRACE in application.properties but still see only INFO logs from com.example classes. What is the most likely cause?
medium
A. Logging is disabled globally
B. TRACE level is not supported in Spring Boot
C. Another configuration overrides the log level to INFO
D. The package name is misspelled in the properties file

Solution

  1. Step 1: Verify if TRACE is supported

    TRACE is a valid log level in Spring Boot, so this is not the issue.
  2. 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.
  3. Final Answer:

    Another configuration overrides the log level to INFO -> Option C
  4. Quick Check:

    Config override causes unexpected log level = D [OK]
Hint: Check for conflicting configs if log level seems ignored [OK]
Common Mistakes:
  • Assuming TRACE is unsupported
  • Not checking for typos in package name
  • Ignoring global logging settings
5. You want to reduce log noise by setting ERROR level for com.example.repository but keep DEBUG for com.example.service. Which application.properties configuration achieves this?
hard
A. logging.level.com.example.repository=ERROR logging.level.com.example.service=DEBUG
B. logging.level.com.example=ERROR logging.level.com.example.service=DEBUG
C. logging.level.com.example.repository=DEBUG logging.level.com.example.service=ERROR
D. logging.level.com.example.repository=INFO logging.level.com.example.service=DEBUG

Solution

  1. Step 1: Set ERROR level specifically for repository package

    Use logging.level.com.example.repository=ERROR to reduce noise from repository logs.
  2. Step 2: Set DEBUG level specifically for service package

    Use logging.level.com.example.service=DEBUG to keep detailed logs for service package.
  3. 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 in application.properties.
  4. Final Answer:

    logging.level.com.example.repository=ERROR logging.level.com.example.service=DEBUG -> Option A
  5. Quick Check:

    Separate package levels set correctly = A [OK]
Hint: Set each package level separately for precise control [OK]
Common Mistakes:
  • Setting parent package level instead of specific packages
  • Swapping log levels between packages
  • Using incorrect property keys or syntax
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard