Bird
Raised Fist0
Spring Bootframework~20 mins

File-based logging in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
File-based Logging Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Log file creation with default Spring Boot logging
You run a Spring Boot application without any custom logging configuration. Which file will be created by default to store logs?
ANo log file is created by default; logs go to console only
Bapplication.log in the current directory
Clogs/app.log inside a logs folder
Dspring.log in the current directory
Attempts:
2 left
💡 Hint
Think about what Spring Boot does if you don't specify any logging file path.
❓ Configuration
intermediate
2:00remaining
Configuring log file location in application.properties
Which property correctly configures Spring Boot to write logs to a file named 'myapp.log' in the 'logs' folder?
Alogging.file=logs/myapp.log
Blogging.path=logs/myapp.log
Clogging.file.path=logs/myapp.log
Dlogging.file.name=logs/myapp.log
Attempts:
2 left
💡 Hint
Check the exact property name for specifying the log file name.
❓ Troubleshoot
advanced
2:00remaining
Log file not created despite configuration
You set 'logging.file.name=logs/app.log' in application.properties, but no log file appears after running the app. What is the most likely cause?
AThe log level is set to ERROR, so no logs are written
BThe 'logs' directory does not exist and Spring Boot does not create it automatically
CThe application.properties file is not in the classpath
DSpring Boot requires a separate logging framework dependency to write files
Attempts:
2 left
💡 Hint
Think about folder creation behavior for log files.
🔀 Workflow
advanced
3:00remaining
Steps to enable rolling log files in Spring Boot
What is the correct order of steps to configure rolling log files using Logback in Spring Boot?
A1,3,2,4
B2,1,3,4
C1,2,3,4
D3,1,2,4
Attempts:
2 left
💡 Hint
Think about creating config, defining appender, linking it, then restarting.
✅ Best Practice
expert
3:00remaining
Best practice for sensitive data in log files
Which approach is best to avoid logging sensitive information like passwords in Spring Boot file logs?
AUse a custom log filter to mask or remove sensitive data before writing logs
BSet logging.level.root=OFF to disable all logging
CWrite sensitive data only to console logs, not files
DEncrypt the entire log file after application shutdown
Attempts:
2 left
💡 Hint
Think about controlling what gets logged rather than disabling logging.

Practice

(1/5)
1. What is the main purpose of file-based logging in a Spring Boot application?
easy
A. To save application messages to a file for later review
B. To send application messages only to the console
C. To delete old log files automatically
D. To encrypt application data before saving

Solution

  1. Step 1: Understand logging basics in Spring Boot

    Logging captures messages about app behavior. File-based logging stores these messages in a file.
  2. Step 2: Identify the purpose of file-based logging

    It allows reviewing logs later for debugging or monitoring, unlike console-only logging.
  3. Final Answer:

    To save application messages to a file for later review -> Option A
  4. Quick Check:

    File-based logging = save logs to file [OK]
Hint: File-based logging means saving logs to a file [OK]
Common Mistakes:
  • Confusing file logging with console logging
  • Thinking it deletes old logs automatically
  • Assuming it encrypts logs by default
2. Which of the following is the correct way to enable file-based logging in application.properties?
easy
A. logging.filepath=logs/app.log
B. logging.file.name=logs/app.log
C. log.file=logs/app.log
D. logging.pathfile=logs/app.log

Solution

  1. Step 1: Recall Spring Boot logging property names

    The correct property to set the log file name is logging.file.name.
  2. Step 2: Check each option for correctness

    Only logging.file.name=logs/app.log uses the exact property logging.file.name with a valid file path.
  3. Final Answer:

    logging.file.name=logs/app.log -> Option B
  4. Quick Check:

    Correct property for log file name = logging.file.name [OK]
Hint: Use logging.file.name to set log file path [OK]
Common Mistakes:
  • Using incorrect property names like logging.filepath
  • Misspelling property keys
  • Confusing logging.file.name with logging.pathfile
3. Given this application.yml snippet:
logging:
  file:
    name: logs/myapp.log
  level:
    root: INFO

What will happen when the Spring Boot app runs?
medium
A. Logs will only print to console with DEBUG level
B. Application will fail to start due to syntax error
C. Logs will be saved to logs/myapp.log but only ERROR level
D. Logs will be saved to logs/myapp.log with INFO level and above

Solution

  1. Step 1: Analyze logging.file.name setting

    The logs will be saved to the file path logs/myapp.log as configured.
  2. Step 2: Analyze logging.level.root setting

    The root log level is INFO, so logs INFO and above will be recorded.
  3. Final Answer:

    Logs will be saved to logs/myapp.log with INFO level and above -> Option D
  4. Quick Check:

    File path + INFO level = logs/myapp.log with INFO+ logs [OK]
Hint: logging.file.name sets file, logging.level.root sets minimum log level [OK]
Common Mistakes:
  • Assuming logs only go to console
  • Confusing log level INFO with DEBUG or ERROR
  • Thinking YAML syntax is invalid here
4. You configured file logging in application.properties as:
logging.file.name=logs/app.log
But no log file is created after running the app. What is the most likely cause?
medium
A. The property should be logging.file.path, not logging.file.name
B. The log level is set to OFF by default
C. The logs directory does not exist and is not created automatically
D. Spring Boot does not support file logging

Solution

  1. Step 1: Check directory existence for log file

    If the logs directory does not exist, Spring Boot may not create it automatically, so no file is created.
  2. Step 2: Verify other options

    Log level defaults to INFO, property name is correct, and Spring Boot supports file logging.
  3. Final Answer:

    The logs directory does not exist and is not created automatically -> Option C
  4. Quick Check:

    Missing log directory = no log file created [OK]
Hint: Ensure log directory exists before running app [OK]
Common Mistakes:
  • Using wrong property name
  • Assuming Spring Boot disables file logging
  • Ignoring missing directory errors
5. You want to keep log files organized by date in Spring Boot. Which configuration snippet in application.yml correctly enables daily rolling log files using Logback?
hard
A. logging: file: name: logs/app.log logback: rollingpolicy: file-name-pattern: logs/app-%d{yyyy-MM-dd}.log
B. logging: file: name: logs/app.log logback: rollingPolicy: filePattern: logs/app-%d{yyyy-MM-dd}.log
C. logging: file: name: logs/app.log logback: rollingpolicy: fileNamePattern: logs/app-%d{yyyy-MM-dd}.log
D. logging: file: path: logs logback: rollingPolicy: fileNamePattern: logs/app-%d{yyyy-MM-dd}.log

Solution

  1. Step 1: Identify correct property names for Logback rolling policy

    The correct key is rollingpolicy (lowercase 'p'), and file-name-pattern (kebab-case) is the correct pattern key.
  2. Step 2: Check each option for exact spelling and structure

    logging: file: name: logs/app.log logback: rollingpolicy: file-name-pattern: logs/app-%d{yyyy-MM-dd}.log uses correct keys: rollingpolicy and file-name-pattern.
  3. Final Answer:

    logging: file: name: logs/app.log logback: rollingpolicy: file-name-pattern: logs/app-%d{yyyy-MM-dd}.log -> Option A
  4. Quick Check:

    Correct keys for rollingpolicy = logging: file: name: logs/app.log logback: rollingpolicy: file-name-pattern: logs/app-%d{yyyy-MM-dd}.log [OK]
Hint: Use exact keys: rollingpolicy and file-name-pattern [OK]
Common Mistakes:
  • Using uppercase 'rollingPolicy' instead of 'rollingpolicy'
  • Using 'filePattern' or 'fileNamePattern' instead of 'file-name-pattern'
  • Confusing logging.file.name with logging.file.path
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