-
Why doesn't this log4j configuration work? I mean the log messages themselves are correct, but the color is missing. The messages are all white, even, for example, Configuration:
Appenders:
Console:
name: CONSOLE
PatternLayout:
pattern: "%highlight{%d{DATE}%n%-5p [%t] : %m%n}"
target: SYSTEM_OUT
File:
name: FILE
PatternLayout:
pattern: "%highlight{%d{DATE}%n%-5p [%t] : %m%n}"
fileName: "src/main/resources/log.txt"
append: false
Loggers:
Root:
level: info
AppenderRef:
- ref: FILE
- ref: CONSOLE My logging dependency is this (I put an <dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>2.20.0</version>
</dependency> Example message (it's in white):
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You are probably using Windows. Since by default To enable Log4j's support for ANSI escapes on Windows you need to:
Remark: If you are using
|
Beta Was this translation helpful? Give feedback.
You are probably using Windows. Since by default
cmd.exe
does not support ANSI escapes, they are disabled on Windows and enabled on all other platforms.To enable Log4j's support for ANSI escapes on Windows you need to:
disableAnsi
to false in your layout:log4j2.skipJansi
tofalse
.Remark: If you are using
cmd.exe
, ANSI escape sequences will not be converted into colors unless:VirtualTerminalLevel
to 1 (see this SO question)