0
0
Spring Bootframework~20 mins

SLF4J and Logback basics in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SLF4J and Logback Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this SLF4J logging code snippet?
Consider this Spring Boot component using SLF4J for logging:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MyService {
private static final Logger logger = LoggerFactory.getLogger(MyService.class);

public void process() {
logger.info("Process started");
logger.debug("Debugging process");
logger.error("Error occurred");
}
}

If the logging level is set to INFO, which messages will appear in the console?
Spring Boot
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MyService {
  private static final Logger logger = LoggerFactory.getLogger(MyService.class);

  public void process() {
    logger.info("Process started");
    logger.debug("Debugging process");
    logger.error("Error occurred");
  }
}
AAll three messages will appear: 'Process started', 'Debugging process', and 'Error occurred'.
BNo messages will appear because INFO level disables all logging.
COnly 'Debugging process' and 'Error occurred' messages will appear.
DOnly 'Process started' and 'Error occurred' messages will appear.
Attempts:
2 left
💡 Hint
Remember that INFO level shows messages at INFO and higher severity.
📝 Syntax
intermediate
2:00remaining
Which Logback configuration snippet correctly sets the root logger to WARN level?
Given these Logback XML configuration options, which one correctly sets the root logger level to WARN?
Spring Boot
<configuration>
  <!-- options below -->
</configuration>
A
&lt;root level="warn"&gt;
  &lt;appender-ref ref="STDOUT" /&gt;
&lt;/root&gt;
B
&lt;root level="Warn"&gt;
  &lt;appender-ref ref="STDOUT" /&gt;
&lt;/root&gt;
C
&lt;root level="WARN"&gt;
  &lt;appender-ref ref="STDOUT" /&gt;
&lt;/root&gt;
D
&lt;root level="warning"&gt;
  &lt;appender-ref ref="STDOUT" /&gt;
&lt;/root&gt;
Attempts:
2 left
💡 Hint
Logback levels are case-sensitive and must be uppercase.
🔧 Debug
advanced
2:00remaining
Why does this SLF4J logging statement cause an error?
Examine this code snippet:
logger.info("User {} logged in at {}", userName);

What error will this cause and why?
Spring Boot
logger.info("User {} logged in at {}", userName);
ASyntax error because of missing semicolon.
BRuntime error due to missing argument for second placeholder.
CNo error; logs message with 'null' for second placeholder.
DCompile-time error due to wrong method signature.
Attempts:
2 left
💡 Hint
Count the placeholders and arguments carefully.
state_output
advanced
2:00remaining
What is the effect of setting additivity to false in Logback logger configuration?
Given this Logback snippet:
<logger name="com.example" level="DEBUG" additivity="false">
  <appender-ref ref="FILE" />
</logger>

What happens to log messages from 'com.example' package?
Spring Boot
<logger name="com.example" level="DEBUG" additivity="false">
  <appender-ref ref="FILE" />
</logger>
AMessages are logged only to FILE appender, not to parent appenders.
BMessages are logged only to parent appenders, ignoring FILE appender.
CMessages are ignored because additivity=false disables logging.
DMessages are logged to FILE and all parent appenders.
Attempts:
2 left
💡 Hint
Additivity controls if logs bubble up to parent loggers.
🧠 Conceptual
expert
3:00remaining
Which statement best describes the relationship between SLF4J and Logback in a Spring Boot application?
Choose the most accurate description of how SLF4J and Logback work together in Spring Boot logging.
ASLF4J is a logging facade that delegates logging calls to Logback, which is the actual logging implementation.
BLogback is a facade that delegates logging calls to SLF4J, which handles the actual logging.
CSLF4J and Logback are independent logging frameworks that cannot be used together.
DSLF4J replaces Logback entirely and provides all logging features by itself.
Attempts:
2 left
💡 Hint
Think about the role of a facade versus an implementation.