0
0
Spring Bootframework~10 mins

SLF4J and Logback basics in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a logger instance using SLF4J in a Spring Boot class.

Spring Boot
private static final Logger logger = LoggerFactory.[1](MyClass.class);
Drag options to blanks, or click blank then click option'
AcreateLogger
BnewLogger
CgetLogger
DbuildLogger
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods like createLogger or newLogger which do not exist.
2fill in blank
medium

Complete the code to log an informational message using SLF4J logger.

Spring Boot
logger.[1]("Application started successfully.");
Drag options to blanks, or click blank then click option'
Awarn
Bdebug
Cerror
Dinfo
Attempts:
3 left
💡 Hint
Common Mistakes
Using debug or error for normal info messages.
3fill in blank
hard

Fix the error in the Logback configuration snippet to set the root logger level to DEBUG.

Spring Boot
<configuration>
  <root level="[1]">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>
Drag options to blanks, or click blank then click option'
Adebug
BDEBUG
CWarn
DINFO
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase like debug or mixed case like Warn.
4fill in blank
hard

Fill both blanks to define a console appender in Logback XML configuration.

Spring Boot
<appender name="STDOUT" class="ch.qos.logback.core.[1]Appender">
  <encoder>
    <pattern>[2]</pattern>
  </encoder>
</appender>
Drag options to blanks, or click blank then click option'
AConsole
B%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
CFile
D%msg%n
Attempts:
3 left
💡 Hint
Common Mistakes
Using FileAppender for console output or wrong pattern strings.
5fill in blank
hard

Fill all three blanks to create a logger and log a warning message with a variable in a Spring Boot class.

Spring Boot
private static final Logger logger = LoggerFactory.[1](MyService.class);

public void checkStatus(String status) {
  logger.[2]("Status is: {}", [3]);
}
Drag options to blanks, or click blank then click option'
AgetLogger
Bwarn
Cstatus
Dinfo
Attempts:
3 left
💡 Hint
Common Mistakes
Using info instead of warn, or forgetting to pass the variable.