logback icon indicating copy to clipboard operation
logback copied to clipboard

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

Open curd0 opened this issue 2 years ago • 17 comments

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

curd0 avatar Dec 18 '23 20:12 curd0

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

alex-konshin avatar Jan 23 '24 20:01 alex-konshin

@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?

ceki avatar Jan 23 '24 20:01 ceki

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

curd0 avatar Jan 23 '24 21:01 curd0

@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.

ceki avatar Jan 23 '24 22:01 ceki

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 avatar Dec 29 '24 07:12 leezm

@leezm This issue was solved in logback version 1.3.7. Have you considered upgrading to version 1.5.x?

ceki avatar Dec 29 '24 19:12 ceki

@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 avatar Dec 30 '24 01:12 leezm

@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.

ceki avatar Dec 30 '24 10:12 ceki

@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:

image

please find attached the code example used to produce this output:

jansi-examples2.zip

curd0 avatar Jan 03 '25 13:01 curd0

@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:

image

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...

leezm avatar Jan 03 '25 13:01 leezm

@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.

ceki avatar Jan 05 '25 23:01 ceki

@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 avatar Jan 06 '25 11:01 ceki

@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?

curd0 avatar Jan 06 '25 16:01 curd0

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.

ceki avatar Jan 06 '25 16:01 ceki

Hello @ceki , what is expected release date for 1.5.17 version?

curd0 avatar Feb 05 '25 15:02 curd0

@curd0 I am afraid there is no expected date. However, for sure there will be no release before the end of February.

ceki avatar Feb 05 '25 16:02 ceki

@ceki thank you for the update.

curd0 avatar Feb 05 '25 17:02 curd0

Logback version 1.5.17 has been released a short time ago.

ceki avatar Feb 25 '25 19:02 ceki

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 !

curd0 avatar Feb 26 '25 00:02 curd0

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 avatar Apr 07 '25 02:04 leibf2099

@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)

curd0 avatar Apr 07 '25 14:04 curd0

@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)

leibf2099 avatar Apr 13 '25 00:04 leibf2099