What is the purpose of log formatting configuration in Spring Boot?
Log formatting configuration controls how log messages appear, making them easier to read and understand by defining the layout, content, and style of log entries.
Click to reveal answer
beginner
Which file is commonly used to configure log formatting in a Spring Boot application?
The application.properties or application.yml file is commonly used for simple log formatting settings, while advanced formatting often uses logback-spring.xml.
Click to reveal answer
intermediate
How do you customize the log pattern in Spring Boot using application.properties?
You set the property logging.pattern.console or logging.pattern.file with a pattern string that defines how each log message should look.
Click to reveal answer
beginner
What is a common pattern syntax element used in log formatting to show the timestamp?
The pattern %d{yyyy-MM-dd HH:mm:ss} is used to display the date and time in logs.
Click to reveal answer
intermediate
Why might you use a logback-spring.xml file instead of application.properties for log formatting?
Because logback-spring.xml allows more detailed and flexible configuration, including multiple appenders, filters, and complex patterns that application.properties cannot handle.
Click to reveal answer
Which property sets the console log format in Spring Boot's application.properties?
Alog.pattern.console
Blogging.format.console
Cspring.logging.console.pattern
Dlogging.pattern.console
✗ Incorrect
The correct property is logging.pattern.console to define the console log format.
What does the pattern %p represent in a log format?
ALog level (e.g., INFO, ERROR)
BLogger name
CThread name
DTimestamp
✗ Incorrect
%p shows the log level like INFO or ERROR.
Which file allows the most advanced log formatting in Spring Boot?
A. 2024-06-01 14:30:00 [main] INFO MyApp - Application started
B. [main] 2024-06-01 14:30:00 INFO MyApp - Application started
C. INFO 2024-06-01 14:30:00 [main] MyApp - Application started
D. MyApp INFO [main] 2024-06-01 14:30:00 - Application started
Solution
Step 1: Analyze the pattern placeholders
%d{yyyy-MM-dd HH:mm:ss} prints date/time, [%thread] prints thread in brackets, %-5level prints log level left-aligned in 5 spaces, %logger{10} prints logger name truncated to 10 chars, %msg prints the message, %n adds newline.
Step 2: Match the pattern to the output options
2024-06-01 14:30:00 [main] INFO MyApp - Application started matches the exact order and format: date, thread in brackets, level padded, logger, dash, message.
Final Answer:
2024-06-01 14:30:00 [main] INFO MyApp - Application started -> Option A
Quick Check:
Pattern placeholders = Output format [OK]
Hint: Match placeholders order exactly to output format [OK]
5. You want to configure your Spring Boot app to log to both console and file with different formats. Which configuration snippet correctly sets a detailed file log pattern and a simple console pattern?