Spring-Boot, improve readability on your console log

Allan Santos
2 min readMay 9, 2019

When we start a Spring-Boot App is it pretty common to see one colored log as showed bellow.

But, as soon as we put our logback-spring.xml inside the project, all the log content turns to blank color.

That happens because is not very common to configure the log pattern, using color information. Fortunately, fix that is very simple. As we can see on the code bellow (piece of logback-spring.xml), is possible use some colors inside the pattern color.

The colors supported are: blue, cyan, faint, green, magenta, red, yellow.

<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date %green(%level) %yellow([%thread]) %cyan(%logger{10}) [%file : %line] %msg%n</pattern>
</encoder>
</appender>

The configuration above will generate something like the code bellow.

At last but not least, it is important to keep in mind two things:
1ª. This configuration will only produce colors, if the console supports ANSI.
2ª. You should not configure those colors at one “appender” different of ConsoleAppender because it not make much sense. if you configure that at one RollingFileAppender, by instance, you will get a file with strange strings like this “DEBUG”.

--

--