Skip to content

The color is missing from my log messages. Why? #1735

Answered by ppkarwasz
NadChel asked this question in Q&A
Discussion options

You must be logged in to vote

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:

  • either set disableAnsi to false in your layout:
    PatternLayout:
       disableAnsi: false
       pattern: "%highlight{%d{DATE}%n%-5p [%t] : %m%n}"
  • or set the system property log4j2.skipJansi to false.

Remark: If you are using cmd.exe, ANSI escape sequences will not be converted into colors unless:

  • you set VirtualTerminalLevel to 1 (see this SO question)
  • or you add Jansi 1.x to your classpath.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@NadChel
Comment options

Answer selected by ppkarwasz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants