Getting Spring Boot color console logging working within Intellij?

Intellij IdeaSpring Boot

Intellij Idea Problem Overview


Has anyone figured out how to get color output working within Intellij Idea for a Spring Boot application?

Intellij Idea Solutions


Solution 1 - Intellij Idea

Using a Mac, Intellij Idea 14 and Spring Boot v1.2.2.RELEASE, all you have to do is set:

spring.output.ansi.enabled=ALWAYS

I have added this as a VM option (-Dspring.output.ansi.enabled=ALWAYS). Works great!

Solution 2 - Intellij Idea

In application.properties use (for example) the following line:

logging.pattern.console= %d{yyyy-MMM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{15}) - %msg %n

If you would like almost similar to Spring Boot you can use pattern like this:

%date  %highlight(%-5level) [%12.12thread] %cyan(%-40.40logger{40}) : %msg %n

Solution 3 - Intellij Idea

Simply by adding those properties to application.properties for IntelliJ IDEA:

spring.main.banner-mode=off 
spring.output.ansi.enabled=ALWAYS

Solution 4 - Intellij Idea

  • install Eclipse plugin called Ansi Console from market place.
  • spring.output.ansi.enabled=ALWAYS @ Application.properties/yml.
  • Run application as spring boot and u will see color logs in console.

Solution 5 - Intellij Idea

yml:

spring:
  output:
    ansi:
      enabled: ALWAYS

Solution 6 - Intellij Idea

Generic way to enable logging color support on any condition with Gradle:

bootRun {
    def console = System.console() != null
    if (! console) { console = System.getenv()["TERM"].startsWith("xterm") }
    if (console) systemProperties 'spring.output.ansi.enabled': 'always'
}

Solution 7 - Intellij Idea

Here is my source of a problem and a solution.

I had two implementation of logging frameworks, which of I was notified immediately after the app was started. You can have even more - all of them are coming from various dependencies. So the message was:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:.../slf4j-simple-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:.../logback-classic-1.1.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]

As you can see there are two found bindings point to two logger frameworks. Each of them is using their own color schema. So which one will be chosen by Spring boot ? According to this tutorial it will get the last one from the list. Which means that your color schema depends now on some pleasantly random choice (have no time to investigate how the list assembles).

After gathering that information about found logging framework bindings I sequentially removed redundant ones from my dependencies.

You can build a maven tree to find the dependency which pulls into your project unwanted SLF4j binding and then exclude it in a maven or gradle configuration file.

Since I am using gradle I just added this configuration to my build.gradle

configurations {
    all {
        exclude group: 'org.slf4j', module: 'slf4j-simple' // no ansi colors in terminal (:
    }
}

This exclusion removes unwanted bindings and returned back my ansi colors to intellij idea terminal (since the only one logging framework left over in my project - and this one has colored output).

Have to notice: if I start my app via mac os terminal by

java -jar fileName.jar

command I do not have colored output.

Solution 8 - Intellij Idea

With newer versions of IntelliJ (2019) and Spring Boot (2.0) when running the a Spring Boot application inside IntelliJ colour logging is correctly output, however when running unit tests no console is detected and so colour logging isn't used. To force Spring Boot to always consider there to be a console even when it can't find one set the following property:

spring.output.ansi.console-available=true

Unlike spring.output.ansi.enabled=ALWAYS this leaves the detection code running (so no colour if you're on windows) but causes colour logging to happen in tests (both in IntelliJ and when running with Maven).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionjoshuawhite929View Question on Stackoverflow
Solution 1 - Intellij Ideajoshuawhite929View Answer on Stackoverflow
Solution 2 - Intellij IdeaKirill ChView Answer on Stackoverflow
Solution 3 - Intellij IdeaHarvester HaidarView Answer on Stackoverflow
Solution 4 - Intellij IdeaJiniView Answer on Stackoverflow
Solution 5 - Intellij IdeaKrzysztofView Answer on Stackoverflow
Solution 6 - Intellij IdeagavenkoaView Answer on Stackoverflow
Solution 7 - Intellij Idead0wnView Answer on Stackoverflow
Solution 8 - Intellij IdeaMatthew BuckettView Answer on Stackoverflow