diff --git a/src/main/java/com/github/games647/colorconsole/common/Log4JInstaller.java b/src/main/java/com/github/games647/colorconsole/common/Log4JInstaller.java index 9125a36..535b5ae 100644 --- a/src/main/java/com/github/games647/colorconsole/common/Log4JInstaller.java +++ b/src/main/java/com/github/games647/colorconsole/common/Log4JInstaller.java @@ -9,6 +9,7 @@ import java.lang.reflect.Method; import java.nio.charset.Charset; import java.util.Collection; import java.util.Map; +import java.util.TreeMap; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.core.Appender; @@ -123,7 +124,10 @@ public class Log4JInstaller { @VisibleForTesting protected String mapLoggingLevels(String logFormat, Map levelColors) { - String levelFormat = Joiner.on(", ").withKeyValueSeparator('=').join(levelColors); + Map sortedColors = new TreeMap<>(); + sortedColors.putAll(levelColors); + + String levelFormat = Joiner.on(", ").withKeyValueSeparator('=').join(sortedColors); return logFormat.replace("%level", "%highlight{%level}{" + levelFormat + '}'); } } diff --git a/src/test/java/com/github/games647/colorconsole/common/Log4JInstallerTest.java b/src/test/java/com/github/games647/colorconsole/common/Log4JInstallerTest.java index 9e52e9c..a101bf6 100644 --- a/src/test/java/com/github/games647/colorconsole/common/Log4JInstallerTest.java +++ b/src/test/java/com/github/games647/colorconsole/common/Log4JInstallerTest.java @@ -39,7 +39,8 @@ public class Log4JInstallerTest { levelColors.put(LoggingLevel.TRACE, "blue"); String configFormat = "[%d{HH:mm:ss} %level]: %msg%n"; - String expected = "[%d{HH:mm:ss} %highlight{%level}{WARN=yellow, ERROR=red, DEBUG=green, FATAL=red, TRACE=blue, INFO=green}]: %msg%n"; + String expected = "[%d{HH:mm:ss} %highlight{%level}{FATAL=red, ERROR=red, WARN=yellow, " + + "INFO=green, DEBUG=green, TRACE=blue}]: %msg%n"; assertThat(installer.mapLoggingLevels(configFormat, levelColors), is(expected)); }