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.

Pattern

Output

What this pattern uses

WordMeaning

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%n

Setting 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:

ModifierEffect
%5levelPad to 5 characters, right-aligned
%-5levelPad to 5 characters, left-aligned
%.30loggerTruncate to 30, keeping the end
%.-30loggerTruncate to 30, keeping the start
%-40.40loggerExactly 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

WordAliasesMeaning
%d{...}%dateTimestamp. Takes a SimpleDateFormat pattern, or ISO8601.
%p%level, %leLog level.
%c{n}%logger{n}Logger name, abbreviated to about n characters.
%m%msg, %messageThe log message.
%nLine separator.
%t%threadThread name.
%X{key}%mdcOne MDC value, or all of them without a key.
%ex%throwable, %wExStack trace, when the event has one.
%F%fileSource file name.
%L%lineSource line number.
%M%methodMethod name.
%C{n}%classFully qualified class name.
%clr(...)Spring Boot's colour wrapper. Colour is stripped when output is not a terminal.