0
0
Spring Bootframework~10 mins

Log formatting configuration in Spring Boot - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Log formatting configuration
Start Application
Load Logging Config
Apply Log Format Settings
Log Event Occurs
Format Log Message
Output to Console/File
Repeat for Next Log Event
This flow shows how Spring Boot loads logging configuration, applies formatting, and outputs logs.
Execution Sample
Spring Boot
logging.pattern.console=%d{HH:mm:ss} %-5level %logger{36} - %msg%n
logger.info("App started")
This config sets console log format; then a log message is printed using that format.
Execution Table
StepActionInput Log EventFormat AppliedOutput Log Message
1Load configN/A%d{HH:mm:ss} %-5level %logger{36} - %msg%nN/A
2Log event triggeredINFO, 'App started'Apply pattern14:23:01 INFO com.example.MyApp - App started
3Log event triggeredERROR, 'Error occurred'Apply pattern14:23:05 ERROR com.example.MyApp - Error occurred
4Log event triggeredDEBUG, 'Debug info'Apply pattern14:23:10 DEBUG com.example.MyApp - Debug info
5Application stopsN/AN/AN/A
💡 Application stops or logging ends
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
logging.pattern.consoleundefined%d{HH:mm:ss} %-5level %logger{36} - %msg%n%d{HH:mm:ss} %-5level %logger{36} - %msg%n%d{HH:mm:ss} %-5level %logger{36} - %msg%n%d{HH:mm:ss} %-5level %logger{36} - %msg%n
log messageN/AINFO, 'App started'ERROR, 'Error occurred'DEBUG, 'Debug info'N/A
formatted outputN/A14:23:01 INFO com.example.MyApp - App started14:23:05 ERROR com.example.MyApp - Error occurred14:23:10 DEBUG com.example.MyApp - Debug infoN/A
Key Moments - 2 Insights
Why does the log message show time and level before the message text?
Because the pattern '%d{HH:mm:ss} %-5level %logger{36} - %msg%n' formats logs to show time, level, logger name, then message as seen in execution_table rows 2-4.
What happens if the logging pattern is missing or incorrect?
Spring Boot uses a default format. The execution_table step 1 shows loading the pattern; if missing, default applies, so logs still print but differently.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what is the log level shown in the output?
AINFO
BERROR
CDEBUG
DWARN
💡 Hint
Check the 'Output Log Message' column at step 3 in execution_table
At which step does the logging pattern get loaded and applied?
AStep 4
BStep 2
CStep 1
DStep 5
💡 Hint
Look at the 'Action' column in execution_table where config is loaded
If the pattern changed to include thread name, how would the output change?
AThread name would appear before the message
BLog level would disappear
CTimestamp would be removed
DLogger name would be replaced by message
💡 Hint
Refer to how pattern controls output format in variable_tracker and execution_table
Concept Snapshot
Log formatting in Spring Boot uses patterns like '%d{HH:mm:ss} %-5level %logger{36} - %msg%n'.
This pattern controls how logs show time, level, logger, and message.
Configured in application.properties or YAML.
Logs use this format each time a log event happens.
Changing pattern changes log appearance immediately.
Full Transcript
In Spring Boot, log formatting configuration controls how log messages appear. The application loads a pattern from configuration files like application.properties. This pattern defines the order and style of log parts such as timestamp, log level, logger name, and message. When a log event happens, Spring Boot applies this pattern to format the message before outputting it to console or file. For example, a pattern '%d{HH:mm:ss} %-5level %logger{36} - %msg%n' shows time, level, logger, and message in that order. If the pattern changes, the log output changes accordingly. This process repeats for every log event until the application stops.