'How to colorize Log4j2 output on console in intelliJ?

I've tried to change the config file to like below but still, the output is plain white. How can I change it to any color? Like different color for each level.

Code:

import org.apache.log4j.*;

public class StartUp {

    private static final Logger LOGGER = Logger.getLogger(Class.class.getName());

    public static void main(String[] args) throws Exception {

        LOGGER.trace("Trace Message!");
        LOGGER.debug("Debug Message!");
        LOGGER.info("Info Message!");
        LOGGER.warn("Warn Message!");
        LOGGER.error("Error Message!");
        LOGGER.fatal("Fatal Message!");

Config file (log4j2.xml):

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <Console name="CONSOLE" target="SYSTEM_OUT">
            <PatternLayout pattern="%highlight{[%d] - %msg%n}{FATAL=red blink, ERROR=red, WARN=yellow bold, INFO=black, DEBUG=green bold, TRACE=blue}"/>
        </Console>
    </Appenders>
    <Loggers>
        <Root level="ALL">
            <AppenderRef ref="CONSOLE"/>
        </Root>
    </Loggers>
</Configuration>


Solution 1:[1]

Use log4j2's stable version 2.9.1 and replace LOGGER initialization with

private static final Logger LOGGER = LogManager.getLogger(Class.class.getName());

Additional documentation about highlighting your console appender: https://logging.apache.org/log4j/2.x/manual/layouts.html

Solution 2:[2]

For IntelliJ I can highly recommend the Grep Console Plugin.

It can parse console output for logs and much more without changing the source code.

enter image description here

Solution 3:[3]

I took both the question and the answer and I have created a colored output similar to the default logback.

Config file (log4j2.xml):

    <?xml version="1.0" encoding="UTF-8"?>
    <Configuration status="WARN" monitorInterval="30">
        <Properties>
            <Property name="CLR">{FATAL=bright red, ERROR=red, WARN=bright yellow, INFO=Normal, DEBUG=white, TRACE=black}</Property>
            <Property name="LOG_PATTERN">
                %highlight{%5p- %d{yy-MM-dd HH:mm:ss.SSS}}${CLR} %clr{${sys:PID}}{magenta}%clr{-}{faint}%clr{[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan}  %highlight{: %m%n%xwEx}${CLR}
            </Property>
        </Properties>
        <Appenders>
            <Console name="Console" target="SYSTEM_OUT" follow="true">
                <PatternLayout pattern="${LOG_PATTERN}" disableAnsi="false"/>
            </Console>
        </Appenders>
    
        <Loggers>
            <logger name="org.springframework.boot.autoconfigure.logging" level="info"/>
            <Root level="debug">
                <AppenderRef ref="Console"/>
            </Root>
        </Loggers>
    </Configuration>

enter image description here

Solution 4:[4]

I'll try to accumulate solutions for this issue, I apologize if I repeated. What should be done to enable the color of the logs in the console (valid only for versions lo4j2 from 2.10, since jansi has been disabled by default)

1) Add jansi dependency:

<dependency>
  <groupId>org.fusesource.jansi</groupId>
  <artifactId>jansi</artifactId>
  <version>1.16</version>
</dependency>

2) Add VM option: -Dlog4j.skipJansi=false

3) And don't forget add %highlight inside pattern (yaml example below):

Configuration:
  Appenders:
    Console:
      PatternLayout:
        pattern: '%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight{%-5level}{STYLE=Logback} %logger.%M - %msg%n'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Kornejew
Solution 3 Ben Rhouma Zied
Solution 4 Bllakus