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
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.
Step 2: Verify other options
Log level defaults to INFO, property name is correct, and Spring Boot supports file logging.
Final Answer:
The logs directory does not exist and is not created automatically -> Option C
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
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.
Step 2: Check each option for exact spelling and structure