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>
Log4j2 ConsoleAppender ConfigurationThe target poperty specifies the target of the logging messages i.e. SYSTEM_OUT or SYSTEM_ERR . The follow attribute tells whether the appender should honor the reassignments of System. out or System. err made after the logging configuration has been initialized.
You can do this: %m{nolookups} in the layout. {nolookups} is how you set the property log4j2. formatMsgNoLookups=true within the configuration XML content.
Configuration: the root element of a log4j2 configuration file; the status attribute represents the level at which internal log4j events should be logged. Appenders: this element contains a list of appenders; in our example, an appender corresponding to the System console is defined.
It seems like some default is broken in 2.10.0. By adding disableAnsi
options, I could get the colors back with the last release.
<PatternLayout pattern="%highlight{...}" disableAnsi="false"/>
In the docs, it is said to default to false
but it doesn't seem the case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With