0
0
Spring Bootframework~10 mins

File-based logging 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 set the logging file name in application.properties.

Spring Boot
logging.file.name=[1]
Drag options to blanks, or click blank then click option'
Aoutput.log
Blogfile.txt
Capp.log
Dserver.log
Attempts:
3 left
💡 Hint
Common Mistakes
Using a directory path instead of a file name
Forgetting the file extension
2fill in blank
medium

Complete the code to set the logging level to DEBUG in application.properties.

Spring Boot
logging.level.root=[1]
Drag options to blanks, or click blank then click option'
ADEBUG
BINFO
CERROR
DWARN
Attempts:
3 left
💡 Hint
Common Mistakes
Using INFO or ERROR which are less detailed
Using invalid logging levels
3fill in blank
hard

Fix the error in the logback-spring.xml snippet to write logs to a file named app.log.

Spring Boot
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
  <file>[1]</file>
  <encoder>
    <pattern>%d{yyyy-MM-dd HH:mm:ss} - %msg%n</pattern>
  </encoder>
</appender>
Drag options to blanks, or click blank then click option'
A/var/log/app
Bapp.log
Clogs/
Dapp
Attempts:
3 left
💡 Hint
Common Mistakes
Using a directory path without file name
Omitting the file extension
4fill in blank
hard

Fill both blanks to configure a rolling file appender with max file size 10MB and max history 5.

Spring Boot
<rollingPolicy class="ch.qos.logback.core.rolling.[1]">
  <maxFileSize>[2]</maxFileSize>
  <maxHistory>5</maxHistory>
</rollingPolicy>
Drag options to blanks, or click blank then click option'
ASizeBasedRollingPolicy
BTimeBasedRollingPolicy
C10MB
D5MB
Attempts:
3 left
💡 Hint
Common Mistakes
Using time-based rolling policy instead of size-based
Setting maxFileSize to 5MB instead of 10MB
5fill in blank
hard

Fill all three blanks to create a log pattern with date, log level, and message.

Spring Boot
<pattern>[1] - [2] - [3]</pattern>
Drag options to blanks, or click blank then click option'
A%d{yyyy-MM-dd HH:mm:ss}
B%level
C%msg
D%thread
Attempts:
3 left
💡 Hint
Common Mistakes
Using thread name instead of log level
Omitting the message part