Logging is very important to debug and diagnose issues while you are developing any application. In Spring Boot 3, some changes have been introduced related to the default format for the date and time component of log messages.
Understanding the New Change
In earlier versions of Spring Boot, the default date and time format for log messages in Logback and Log4j2 was different wherein the date and time components were separated by space.
yyyy-MM-dd HH:mm:ss.SSS
ShellScriptIn Spring Boot 3, the new default date and time format for log messages has changed. The new default format aligns with the ISO-8601 standard and uses the following format:
yyyy-MM-dd’T’HH:mm:ss.SSSXXX
ShellScriptThe main difference is that a “T” is used to separate the date and time instead of a space character, and the timezone offset is added to the end of the format.
Restoring the Previous Default Format
If you want to restore the previous default value of yyyy-MM-dd HH:mm:ss.SSS
, you can use the LOG_DATEFORMAT_PATTERN
environment variable or logging.pattern.dateformat
property. This will override the new default value and restore the previous format.
Using the logging.pattern.dateformat
Property
To use the logging.pattern.dateformat
property, you can set it in your application.properties or inside the application.yaml file as follows:
logging.pattern.dateformat=yyyy-MM-dd HH:mm:ss.SSS
application.propertieslogging:
pattern:
dateformat: yyyy-MM-dd HH:mm:ss.SSS
application.yamlSummary
With the recent changes in Spring Boot 3 related to the default date and time format in Logback and Log4j2, it is very important to understand the new default format and how to restore the previous default format if needed. By following the steps mentioned above, you can ensure that your application’s logs are formatted exactly the way you want them.
Bonus
Curious to Learn Something New?
Check out how to handle trailing slash changes in Spring Boot 3.
Add a Comment