Spring Boot log pattern tester
Edit the pattern and watch the sample output change. The usual way to check alogging.pattern.console change is to restart the application and squint at the console — this does the same job in the browser.
Output
What this pattern uses
| Word | Meaning |
|---|
Setting it in Spring Boot
Console and file output take separate patterns:
logging.pattern.console=%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n
logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger - %msg%nSetting logging.pattern.console replaces Spring Boot's default entirely, colour included. Keep the %clr(...) wrappers if you want to keep the colours.
Width and truncation
The number between % and the word is a minimum width, and the one after a dot is a maximum:
| Modifier | Effect |
|---|---|
%5level | Pad to 5 characters, right-aligned |
%-5level | Pad to 5 characters, left-aligned |
%.30logger | Truncate to 30, keeping the end |
%.-30logger | Truncate to 30, keeping the start |
%-40.40logger | Exactly 40 characters, left-aligned |
Truncation defaults to keeping the end because that is the part of a logger name that identifies the class. Fixing a column at %-40.40 is what keeps messages aligned down the console.
Abbreviating the logger name
%logger{n} does not simply cut the string. It shortens package segments to a single letter, left to right, stopping at the longest form that fits — socom.example.demo.service.OrderService at {20} becomesc.e.d.s.OrderService, and the class name always survives intact.%logger{0} keeps only the class name.
Cost worth knowing: %F, %L, %M and%C make Logback build a stack trace for every log event. It is fine in development and measurably slow in a hot path.
Conversion words
| Word | Aliases | Meaning |
|---|---|---|
%d{...} | %date | Timestamp. Takes a SimpleDateFormat pattern, or ISO8601. |
%p | %level, %le | Log level. |
%c{n} | %logger{n} | Logger name, abbreviated to about n characters. |
%m | %msg, %message | The log message. |
%n | Line separator. | |
%t | %thread | Thread name. |
%X{key} | %mdc | One MDC value, or all of them without a key. |
%ex | %throwable, %wEx | Stack trace, when the event has one. |
%F | %file | Source file name. |
%L | %line | Source line number. |
%M | %method | Method name. |
%C{n} | %class | Fully qualified class name. |
%clr(...) | Spring Boot's colour wrapper. Colour is stripped when output is not a terminal. |