Bird
Raised Fist0
Spring Bootframework~20 mins

Log formatting configuration in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Log Formatting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
Understanding log pattern output in Spring Boot
Given this log pattern configuration in Spring Boot:
logging.pattern.console=%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n

What will be the output format of a log entry?
ATime in hours, minutes, seconds, milliseconds, thread name in brackets, log level left-padded to 5 chars, logger name truncated to 36 chars, message, newline
BDate in yyyy-MM-dd format, thread name in brackets, log level right-padded to 5 chars, full logger name, message, newline
CTimestamp in milliseconds, thread name without brackets, log level uppercase, logger name full, message, newline
DTime in HH:mm:ss format, thread id in brackets, log level left-padded to 5 chars, logger name truncated to 20 chars, message, newline
Attempts:
2 left
💡 Hint
Look carefully at the pattern symbols: %d{HH:mm:ss.SSS}, [%thread], %-5level, %logger{36}, %msg%n
📝 Syntax
intermediate
2:00remaining
Identify the invalid log pattern syntax
Which of the following Spring Boot log pattern configurations will cause a syntax error or fail to format logs correctly?
Alogging.pattern.console=%d{HH:mm:ss.SSS [%thread] %-5level %logger{36} - %msg%n
Blogging.pattern.console=%d{HH:mm:ss} [%thread] %-5level %logger{20} - %msg%n
Clogging.pattern.console=%d{HH:mm:ss.SSS} [%thread] %level %logger{36} - %msg%n
Dlogging.pattern.console=%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n
Attempts:
2 left
💡 Hint
Check for missing or misplaced braces and brackets in the pattern.
❓ state_output
advanced
2:00remaining
Effect of changing log pattern on output
If you change the Spring Boot log pattern from:
%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n

to:
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{10} - %msg%n

What is the main visible difference in the log output?
AThe message will be omitted from the output, showing only metadata.
BThe timestamp will show only time with milliseconds, and the logger name will be fully displayed.
CThe timestamp will include the full date and time, and the logger name will be truncated to 10 characters instead of 36.
DThe thread name will be removed from the output, and the log level will be right-padded.
Attempts:
2 left
💡 Hint
Compare the date format and logger name length in both patterns.
🔧 Debug
advanced
2:00remaining
Diagnose missing thread name in logs
You configured your Spring Boot log pattern as:
logging.pattern.console=%d{HH:mm:ss.SSS} %thread %-5level %logger{36} - %msg%n

But the logs do not show the thread name in brackets as expected. What is the cause?
AThe %thread placeholder is invalid and should be %t instead.
BThe logger name truncation %logger{36} removes the thread name from output.
CThe log level placeholder %-5level must come before the thread name to show it correctly.
DThe pattern is missing brackets around %thread, so thread name appears without brackets.
Attempts:
2 left
💡 Hint
Look at how the thread name is enclosed in the pattern.
🧠 Conceptual
expert
2:00remaining
Understanding log pattern placeholders and their effects
Which of the following statements about Spring Boot log pattern placeholders is TRUE?
A%level outputs the log level in uppercase by default.
B%msg outputs the log message without a newline character.
C%logger{length} truncates the logger name to the specified number of characters from the end.
D%thread outputs the thread ID number instead of the thread name.
Attempts:
2 left
💡 Hint
Recall what each placeholder outputs exactly.

Practice

(1/5)
1. What is the purpose of configuring log formatting in a Spring Boot application?
easy
A. To disable logging completely
B. To increase the size of log files automatically
C. To make logs easier to read and understand by customizing their appearance
D. To encrypt log messages for security

Solution

  1. Step 1: Understand the role of log formatting

    Log formatting controls how log messages appear, making them clearer and easier to read.
  2. Step 2: Identify the main goal of formatting

    The main goal is to customize the log output for better readability, not to disable or encrypt logs.
  3. Final Answer:

    To make logs easier to read and understand by customizing their appearance -> Option C
  4. Quick Check:

    Log formatting = Customize log appearance [OK]
Hint: Log formatting improves readability, not disables logging [OK]
Common Mistakes:
  • Thinking log formatting disables logs
  • Confusing formatting with log encryption
  • Assuming formatting increases log file size
2. Which of the following is the correct way to set a simple console log pattern in application.properties?
easy
A. console.logging.pattern=%date %level %logger %message
B. logging.pattern.console=%d{HH:mm:ss} %-5level %logger{36} - %msg%n
C. logging.console.pattern=%d{HH:mm:ss} %level %logger - %msg
D. logging.pattern=%d %level %logger %msg

Solution

  1. Step 1: Identify the correct property key for console log pattern

    The correct key is logging.pattern.console in Spring Boot.
  2. Step 2: Check the pattern syntax

    The pattern uses placeholders like %d for date, %-5level for log level, %logger{36} for logger name, and %msg for message, ending with %n for newline.
  3. Final Answer:

    logging.pattern.console=%d{HH:mm:ss} %-5level %logger{36} - %msg%n -> Option B
  4. Quick Check:

    Correct property and pattern syntax = logging.pattern.console=%d{HH:mm:ss} %-5level %logger{36} - %msg%n [OK]
Hint: Use logging.pattern.console for console logs in application.properties [OK]
Common Mistakes:
  • Using wrong property keys like logging.console.pattern
  • Missing newline %n at the end
  • Incorrect placeholder syntax
3. Given this configuration in application.properties:
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{10} - %msg%n
What will be the output format of a log message?
medium
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

  1. 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.
  2. 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.
  3. Final Answer:

    2024-06-01 14:30:00 [main] INFO MyApp - Application started -> Option A
  4. Quick Check:

    Pattern placeholders = Output format [OK]
Hint: Match placeholders order exactly to output format [OK]
Common Mistakes:
  • Mixing order of thread and date
  • Ignoring padding in log level
  • Confusing logger truncation
4. You set this in application.properties:
logging.pattern.file=%d{HH:mm:ss} %level %logger - %msg%n
But your log file shows no timestamps. What is the likely cause?
medium
A. The timestamp format %d{HH:mm:ss} is invalid and causes logs to skip it
B. The pattern uses %level instead of %-5level, causing timestamp omission
C. The property key should be logging.pattern.file instead of logging.pattern.file
D. The logging system ignores the pattern if the file appender is not configured properly

Solution

  1. Step 1: Verify property key correctness

    The property key logging.pattern.file is correct for file log pattern in Spring Boot.
  2. Step 2: Consider logging system configuration

    If the file appender is not properly set up, the pattern may be ignored, causing missing timestamps.
  3. Final Answer:

    The logging system ignores the pattern if the file appender is not configured properly -> Option D
  4. Quick Check:

    File appender config missing = pattern ignored [OK]
Hint: Check file appender setup if pattern changes don't appear [OK]
Common Mistakes:
  • Assuming %level causes timestamp issues
  • Thinking property key is wrong
  • Believing timestamp format is invalid
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?
hard
A. logging.pattern.console=%d{HH:mm:ss} %-5level %msg%n logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
B. logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n logging.pattern.file=%d{HH:mm:ss} %-5level %msg%n
C. logging.pattern.console=%msg%n logging.pattern.file=%msg%n
D. logging.console.pattern=%d{HH:mm:ss} %level %msg logging.file.pattern=%d{yyyy-MM-dd} %level %logger %msg

Solution

  1. Step 1: Identify correct property keys for console and file patterns

    Spring Boot uses logging.pattern.console and logging.pattern.file keys.
  2. Step 2: Check pattern details for console and file

    Console pattern is simple with time, level, and message. File pattern is detailed with full timestamp, thread, level, logger, and message.
  3. Step 3: Match options to correct keys and patterns

    logging.pattern.console=%d{HH:mm:ss} %-5level %msg%n logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n correctly sets simple console and detailed file patterns with proper keys and placeholders.
  4. Final Answer:

    logging.pattern.console=%d{HH:mm:ss} %-5level %msg%n logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n -> Option A
  5. Quick Check:

    Correct keys and patterns for console and file = logging.pattern.console=%d{HH:mm:ss} %-5level %msg%n logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n [OK]
Hint: Use logging.pattern.console and logging.pattern.file keys for different formats [OK]
Common Mistakes:
  • Swapping console and file property keys
  • Using incorrect property keys like logging.console.pattern
  • Using overly simple patterns for file logs
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