From b0b5fde74219f7bcae35cfff0370a55e0dd62272 Mon Sep 17 00:00:00 2001 From: phytohydra <144396848+phytohydra@users.noreply.github.com> Date: Fri, 29 Mar 2024 10:47:59 +0000 Subject: [PATCH] Remove coloring of log.info messages (#851) --- .../haveno/common/app/LogHighlighter.java | 36 +++++++++++++++++++ desktop/src/main/resources/logback.xml | 5 ++- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 common/src/main/java/haveno/common/app/LogHighlighter.java diff --git a/common/src/main/java/haveno/common/app/LogHighlighter.java b/common/src/main/java/haveno/common/app/LogHighlighter.java new file mode 100644 index 00000000..cec16a5f --- /dev/null +++ b/common/src/main/java/haveno/common/app/LogHighlighter.java @@ -0,0 +1,36 @@ +/* Derived from https://logback.qos.ch/xref/ch/qos/logback/classic/pattern/color/HighlightingCompositeConverter.html */ + +package haveno.common.app; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.spi.ILoggingEvent; +import static ch.qos.logback.core.pattern.color.ANSIConstants.BOLD; +import static ch.qos.logback.core.pattern.color.ANSIConstants.DEFAULT_FG; +import static ch.qos.logback.core.pattern.color.ANSIConstants.RED_FG; +import ch.qos.logback.core.pattern.color.ForegroundCompositeConverterBase; + +/** + * Highlights inner-text depending on the level, in bold red for events of level + * ERROR, in red for WARN, in the default color for INFO, and in the default color for other + * levels. + */ + +public class LogHighlighter extends ForegroundCompositeConverterBase { + + @Override + protected String getForegroundColorCode(ILoggingEvent event) { + Level level = event.getLevel(); + switch (level.toInt()) { + case Level.ERROR_INT: + return BOLD + RED_FG; + case Level.WARN_INT: + return RED_FG; + case Level.INFO_INT: + return DEFAULT_FG; + default: + return DEFAULT_FG; + } + + } +} + diff --git a/desktop/src/main/resources/logback.xml b/desktop/src/main/resources/logback.xml index 668bfe09..baca4a0a 100644 --- a/desktop/src/main/resources/logback.xml +++ b/desktop/src/main/resources/logback.xml @@ -1,8 +1,11 @@ + + + - %highlight(%d{MMM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{30}: %msg %xEx%n) + %hl2(%d{MMM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{30}: %msg %xEx%n)