Jansi 2.4.0 color-coded output not working properly on CMD.EXE console
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
Here's the output produced on the same machine in CMD.EXE console:
and in Windows Terminal:
I have the same problem. Would be great if someone would look at this issue.
@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?
Hello @ceki, the problem was originally reported on Windows 2019 Server, but I could also reproduce it on my development Windows 11 Enterprise machine:
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:
@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.
The same problem, when I use the logback1.2.12 version that comes with spring boot, when I use jansi2.4.1, the cmd window on winserver2016 is not colored, and it will take effect when I switch to jansi version 1.18.
@leezm This issue was solved in logback version 1.3.7. Have you considered upgrading to version 1.5.x?
@leezm This issue was solved in logback version 1.3.7. Have you considered upgrading to version 1.5.x?
Unfortunately, I use jdk1.8, Spring Boot Starter Web 2.7.18, and when I specify logback separately to version 1.3.7 or the latest 1.5.x, there will be compatibility issues...
@leezm The 1.2.x branch is no longer being actively developed and there are no plans to fix this issue for 1.2.x.
@leezm This issue was solved in logback version 1.3.7. Have you considered upgrading to version 1.5.x?
@ceki what issue are you referring to? I'm using the latest Logback 1.5.15 and still have the same problem with jansi:
please find attached the code example used to produce this output:
@leezm This issue was solved in logback version 1.3.7. Have you considered upgrading to version 1.5.x?
@ceki what issue are you referring to? I'm using the latest Logback 1.5.15 and still have the same problem with jansi:
please find attached the code example used to produce this output:
jansi-examples2.zip I know, as I mentioned above, I am using jdk1.8, spring boot 2.7.18, and encountered jar package compatibility issues after upgrading, so I will temporarily use the old version of jansi to solve it...
@curd0 Thank you for providing the examples file. I have tested your example on "Windows 11 Home" with the CMD console with no problems.
Update: However, changing the terminal type to "Windows Console Host" I can reproduce the issue.
@curd0 Calling AnsiConsole.systemInstall() fixes the the issue for "Windows Console Host"/Jansi 2.x as well. See commit 51e390303eb27a70b. Could you please verify?
@ceki I confirm that the issue is fixed by adding AnsiConsole.systemInstall() to the example class:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.fusesource.jansi.AnsiConsole;
public class JansiLogback {
private static final Logger logger = LoggerFactory.getLogger(JansiLogback.class);
public static void main(String[] args) {
AnsiConsole.systemInstall(); // <--------------- HERE
logger.debug("DEBUG from {}", JansiLogback.class.getSimpleName());
logger.info ("INFO from {}", JansiLogback.class.getSimpleName());
logger.warn ("WARNING from {}", JansiLogback.class.getSimpleName());
logger.error("ERROR from {}", JansiLogback.class.getSimpleName());
}
}
Am I right to expect that adding AnsiConsole.systemInstall() to my code won't be necessary when logback 1.5.17 (including https://github.com/qos-ch/logback/commit/51e390303eb27a70b16b0b8902e0240bb79f7d51) is released?
Am I right to expect that adding AnsiConsole.systemInstall() to my code won't be necessary when logback 1.5.17 (including https://github.com/qos-ch/logback/commit/51e390303eb27a70b16b0b8902e0240bb79f7d51) is released?
Yes, that is a reasonable assumption.
Hello @ceki , what is expected release date for 1.5.17 version?
@curd0 I am afraid there is no expected date. However, for sure there will be no release before the end of February.
@ceki thank you for the update.
Logback version 1.5.17 has been released a short time ago.
Logback version 1.5.17 has been released a short time ago.
I confirm that the reported color-coded output issue is no longer reproducible with 1.5.17. Thank you so much, @ceki !
windows ok, but linux,logback 1.5.18 with Jansi 2.4.1 in the terminal console, the logback fails to produce color-coded output, but Jansi 1.18 ok
@leibf2099 what Linux do you use?
logback 1.5.18 + Jansi 2.4.1 work fine for me on CentOS Linux 7.9, RHEL 8.8, and in WSL2 (Ubuntu 24.04)
@leibf2099 what Linux do you use?
logback 1.5.18 + Jansi 2.4.1 work fine for me on CentOS Linux 7.9, RHEL 8.8, and in WSL2 (Ubuntu 24.04)
Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-1121-raspi aarch64)
