Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LOGBACK-1392 Improve support for the JANSI library in ConsoleAppender #414

Merged
merged 2 commits into from
Oct 9, 2019

Conversation

adutra
Copy link
Contributor

@adutra adutra commented Mar 23, 2018

Motivation:

The Jansi library provides an AnsiPrintStream that intercepts ANSI
sequences and allows the application to react to them accordingly.
Jansi is compatible with a variety of terminals, including xterm-like
terminals for Windows like Mintty and MinGW.

Jansi has a good algorithm to detect whether or not ANSI
sequences will be correctly interpreted or not, and if not, its default
behavior is to filter out such sequences.

Logback's ConsoleAppender has a withJansi option. Unfortunately,
Logback bypasses Jansi's detection algorithm and boldly
assumes that if the OS is Windows, then the terminal is a DOS prompt.
So while DOS prompts get colored, terminals like Mintty or MinGW not
only lose their coloring but are sent DOS escape sequences that they
can't interpret.

Modifications:

  • Amend ConsoleAppender so that when withJansi is true, then all
    OutputStreams are wrapped in an AnsiPrintStream, effectively delegating
    to the JANSI library the decision to filter out ANSI escape sequences
    or not, depending on the terminal capability. This also allows users
    to disable or customize the coloring behavior by using system properties
    recognized by JANSI, such as jansi.strip.
  • Amend the documentation and stress that the JANSI library is the
    recommended solution for Windows systems, as well as for cross-platform
    deployments that include a mix of Windows and non-Windows systems.

@ceki
Copy link
Member

ceki commented Mar 23, 2018

@adutra Can you create a Jira issue for this PR please?

@adutra adutra changed the title Improve support for the JANSI library LOGBACK-1392 Improve support for the JANSI library in ConsoleAppender Mar 24, 2018
@adutra
Copy link
Contributor Author

adutra commented Mar 24, 2018

@ceki of course, there you go: LOGBACK-1392

@adutra adutra force-pushed the adutra-jansi-enhancements branch 3 times, most recently from 697e644 to 66d6432 Compare March 26, 2018 07:51
Motivation:

The Jansi library provides an AnsiPrintStream that intercepts ANSI
sequences and allows the application to react to them accordingly.
Jansi is compatible with a variety of terminals, including xterm-like
terminals for Windows like Mintty and MinGW.

Jansi has a good algorithm to detect whether or not ANSI
sequences will be correctly interpreted or not, and if not, its default
behavior is to filter out such sequences.

Logback's ConsoleAppender has a withJansi option. Unfortunately,
Logback bypasses Jansi's detection algorithm and boldly
assumes that if the OS is Windows, then the terminal is a DOS prompt.
So while DOS prompts get colored, terminals like Mintty or MinGW not
only lose their coloring but are sent DOS escape sequences that they
can't interpret.

Modifications:

- Amend ConsoleAppender so that when withJansi is true, then all
OutputStreams are wrapped in an AnsiPrintStream, effectively delegating
to the JANSI library the decision to filter out ANSI escape sequences
or not, depending on the terminal capability. This also allows users
to disable or customize the coloring behavior by using system properties
recognized by JANSI, such as jansi.strip.
- Amend the documentation and stress that the JANSI library is the
recommended solution for Windows systems, as well as for cross-platform
deployments that include a mix of Windows and non-Windows systems.
@sbernard31
Copy link

Is there plan to integrate this PR in next version of LOGBACK ?

@sbernard31
Copy link

More than one year and this PR is still not integrated any reason of that ?

@ceki
Copy link
Member

ceki commented Oct 8, 2019

Looks quite good. My apologies for the delay.

If the code is not merged by this Thursday evening, please remind me once again.

@ceki ceki merged commit 62ccef8 into qos-ch:master Oct 9, 2019
@sbernard31
Copy link

Thx 🙏 !

@sbernard31
Copy link

Is there any chance this could be backported in 1.2.x branch ?
(I ask this because I saw that 1.3.0 will need java 8 and I'm stucked to java 7)

Out of topic question ? do you have a vague idea about when the 1.3.0 will be released ?

@sbernard31
Copy link

sbernard31 commented Aug 3, 2021

I finally find a workaround about this using Picocli heuristic : https://stackoverflow.com/a/68633212/5088764

(in my case that solve the java8 and Jansi dependency but It would be better that logback has its own heuristic like requested in https://jira.qos.ch/browse/LOGBACK-1430)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants