1

A "gradle run" of a Java application on a Linux terminal (xfce4-terminal) that outputs SLF4J logs prints all text in plain boring white.

To clarify a bit more, I'd like this to happen automatically without any change to existing log statements.

What's the best way to color those ERROR/WARN/INFO/DEBUG output lines? (Ex. Red/Yellow/Green/Blue)

Manius
  • 3,594
  • 3
  • 34
  • 44
  • What is the log implementation behind SLF4J? log4j or kogback? – life888888 Feb 28 '23 at 03:39
  • 1
    Does this answer your question? [Logback: use colored output only when logging to a real terminal](https://stackoverflow.com/questions/31046748/logback-use-colored-output-only-when-logging-to-a-real-terminal) – life888888 Feb 28 '23 at 03:40
  • Ah forgot - Logback preferred. – Manius Feb 28 '23 at 04:28
  • The link MIGHT help I'll have to look it over closer when I have time. – Manius Feb 28 '23 at 04:30
  • I wouldn't say the link is an answer since that requirement is much more complicated, but there was a link to a useful portion of the documentation there. – Manius Feb 28 '23 at 23:59

1 Answers1

0

Easy once you find it in the docs. I've been all over those docs but had no idea this was built in. You may need the "withJansi" boolean set (unless you're on Linux/Unix, see docs) and then you can use %highlight([whatever to colorize]) inside your encoder pattern.

https://logback.qos.ch/manual/layouts.html#coloring

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    <withJansi>true</withJansi>
    <encoder>
        <pattern>[%thread] %highlight(%-5level) %logger{0} - %msg%n</pattern>
    </encoder>
</appender>

(Don't just copy/paste that pattern above since it's missing date/time and usually you'll want that...)

Manius
  • 3,594
  • 3
  • 34
  • 44