Reputation: 131
My application contains jruby jar which contains jansi.jar
and native libraries for ANSI escape.
When log4j2 notices jansi.jar
in the classpath, it tries to initialize ANSI escaped logging.
But I don't want any color logs. So, how do I configure log4j2 to avoid color logs?
This is my pattern expression:
%d{yyyy-MM-dd}T%d{HH:mm:ss,SSS} %level{length=1} %-20t %-30F %m%xEx{short}%n
Upvotes: 3
Views: 4660
Reputation: 131
I figured out the issue. I was using a writing to STDOUT which uses ConsoleAppender. Inside the ConsoleAppender L120 in version 2.0-rc1 of log4j2 core jar, log4j2 looks for jansi library. I just turned off the Console logging to get around this issue.
Upvotes: 1
Reputation: 5618
According to the Log4j2 manual, this coloring feature is enabled using the highlight
or style
keyword in your pattern, so your log should not use ANSI color since your Pattern does not contain such keyword. Are you sure that the Pattern you gave here is the one used for your appender?
Have you tried surrounding your pattern with %style{...}{Normal}
to force default style, even if ANSI escaped mode is on? Like:
%style{%d{yyyy-MM-dd}T%d{HH:mm:ss,SSS} %level{length=1} %-20t %-30F %m%xEx{short}%n}{Normal}
Although, you might be interested in this manual's remark:
ANSI Styling on Windows
ANSI escape sequences are supported natively on many platforms but are not by default on Windows. To enable ANSI support simply add the Jansi jar to your application and Log4j will automatically make use of it when writing to the console.
Note that if no console is attached to your process, Log4j2 RC1 now doesn't automatically use ANSI escape anymore (was a bug in beta versions): https://issues.apache.org/jira/browse/LOG4J2-413.
Upvotes: 2