qos-ch / logback

The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch
Other
2.98k stars 1.28k forks source link

Jansi 2.4.0 color-coded output not working properly on CMD.EXE console #753

Open curd0 opened 8 months ago

curd0 commented 8 months ago

On Windows, when I use logback 1.4.14 with Jansi 2.4.0 in the old CMD.EXE console, the logback fails to produce color-coded output. The same code executed in Windows Terminal works as expected.

Interestingly, substituting the current Jansi 2.4.0 with an older Jansi 1.18, seems to fix the issue. This suggests that there might be some differences in the newer versions of Jansi that Logback doesn't handle very well.

The following ZIP contains a simple example (requires Java 11+) that produces colored output using standalone Jansi 1.18 and 2.4.0, and Logback with Jansi 1.18 and 2.4.0. To execute: extract and run jansi-examples.bat

jansi-examples.zip

Here's the output produced on the same machine in CMD.EXE console:

image

and in Windows Terminal:

image

alex-konshin commented 7 months ago

I have the same problem. Would be great if someone would look at this issue.

ceki commented 7 months ago

@curd0 Thank you for this report.

Testing on "Windows 11 Home" and Java 21, it all looks good. Which version of Windows and Java are you testing with?

curd0 commented 7 months ago

Hello @ceki, the problem was originally reported on Windows 2019 Server, but I could also reproduce it on my development Windows 11 Enterprise machine:

image

The version of Java doesn't seem relevant, I'm getting the same output with Java 11, 17, and 21.

Please note, that the problem is only reproducible in old CMD.EXE console. If you have Windows Terminal installed on your machine, then, by default, when you try to start CMD.EXE Windows starts Windows Terminal instead.

To change that default (you can reverse it later) pick "Windows Console Host" as a default terminal application in Windows Terminal Settings:

image

ceki commented 7 months ago

@curd0 Thank you. I can reproduce the problem.

ConsoleAppender does not invoke AnsiConsole.systemInstall() which seems to make difference. Under Windows, in Jansi 1.x it seems to work regardless but not in Jansi 2.x.