Close

Spring Boot - Enabling Color Coded Output

[Last Updated: Sep 22, 2017]

Spring boot can display ANSI color coded output if the target terminal supports it. We need to set spring.output.ansi.enabled property. The possible values are ALWAYS, DETECT and NEVER.

Example

src/main/resources/application.properties

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

Note that the property spring.output.ansi.enabled is set to 'DETECT' value by default, but not all terminals will show the colored output unless we set it to 'ALWAYS'. Also if we set the value 'ALWAYS' and if the target terminal does not support ANSI codes then instead of colored output, the raw embedded color codes will be shown in the logs.

An example bean

package com.logicbig.example;

import org.springframework.stereotype.Component;

import java.util.logging.Logger;

@Component
public class MyBean {
  private static final Logger logger = Logger.getLogger(MyBean.class.getName());

  public void doSomething() {
      logger.info("some message");
  }
}

The Main class

@SpringBootApplication
public class ExampleMain {

  public static void main(String[] args) throws InterruptedException {
      ConfigurableApplicationContext context =
              SpringApplication.run(ExampleMain.class, args);
      MyBean bean = context.getBean(MyBean.class);
      bean.doSomething();
  }
}

Output

Intellij

IntelliJ shows the colored output without any extra configuration. Running the main class (IntelliJ Community Edition 2016.3):

Eclipse

In Eclipse, you have to install an additional plugin from here. Running the main class (Eclipse 4.6.0 - Neon):

Windows power shell

Running from Windows 10 PowerShell

 mvn -q spring-boot:run

It does not work in Windows cmd.exe.

Bash running in Linux Mint

Running the executable jar of above example in Linux Mint (18.1) accessed via putty.

 java -jar boot-color-console-output.jar

The standalone executable jar above was created with Spring Boot Maven plugin.

Example Project

Dependencies and Technologies Used:

  • Spring Boot 1.5.7.RELEASE
    Corresponding Spring Version 4.3.11.RELEASE
  • spring-boot-starter : Core starter, including auto-configuration support, logging and YAML.
  • JDK 1.8
  • Maven 3.3.9

Color-coded Console Output Example Select All Download
  • boot-color-console-output
    • src
      • main
        • java
          • com
            • logicbig
              • example
        • resources
          • application.properties

    See Also