How to configure logback in spring-boot for ANSI color function?

I have a spring-boot application running on Windows. I added the jansi project (v1.8) to the project to enable the output of color terminals in windows.

We included the log configuration presented in spring-boot, added the following line to logback.xml.

<include resource="org/springframework/boot/logging/logback/base.xml" /> 

It is not clear how to configure logback.xml so that its log statements are colored according to the underlying .xml provided by spring-boot. Sorry if this is a really stupid question, I'm new to logback.

Thanks!

+6
source share
2 answers
+6
source

This is described in the coloring section of the log documentation:

Grouping by parentheses, as described above, allows you to colorize the submatrices. Starting with version 1.0.5, PatternLayout recognizes "% black", "% red", "% green", "% yellow", "% blue", "% magenta", "% cyan", "% white", " % gray ","% boldRed ","% boldGreen ","% boldYellow ","% boldBlue ","% boldMagenta ","% boldCyan ","% boldWhite "and"% highlight "as conversion words. These conversion words are intended to contain a sub-pattern. Any sub-template enclosed in a colored word will be displayed in the specified color.

There is also an example configuration file that shows how to use conversion words:

 <configuration debug="true"> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <!-- On Windows machines setting withJansi to true enables ANSI color code interpretation by the Jansi library. This requires org.fusesource.jansi:jansi:1.8 on the class path. Note that Unix-based operating systems such as Linux and Mac OS X support ANSI color codes by default. --> <withJansi>true</withJansi> <encoder> <pattern>[%thread] %highlight(%-5level) %cyan(%logger{15}) - %msg %n</pattern> </encoder> </appender> <root level="DEBUG"> <appender-ref ref="STDOUT" /> </root> </configuration> 
+12
source

Source: https://habr.com/ru/post/980712/


All Articles