diff --git a/src/main/java/com/github/games647/colorconsole/ColorConsole.java b/src/main/java/com/github/games647/colorconsole/ColorConsole.java index 6d474fb..d7f1ac9 100644 --- a/src/main/java/com/github/games647/colorconsole/ColorConsole.java +++ b/src/main/java/com/github/games647/colorconsole/ColorConsole.java @@ -77,7 +77,7 @@ public class ColorConsole extends JavaPlugin { if (getConfig().getBoolean("colorPluginTag")) { Logger rootLogger = ((Logger) LogManager.getRootLogger()); - ColorPluginAppender pluginAppender = new ColorPluginAppender(terminalAppender); + ColorPluginAppender pluginAppender = new ColorPluginAppender(terminalAppender, this); pluginAppender.start(); rootLogger.removeAppender(terminalAppender); diff --git a/src/main/java/com/github/games647/colorconsole/ColorPluginAppender.java b/src/main/java/com/github/games647/colorconsole/ColorPluginAppender.java index 85c3d59..bcfed22 100644 --- a/src/main/java/com/github/games647/colorconsole/ColorPluginAppender.java +++ b/src/main/java/com/github/games647/colorconsole/ColorPluginAppender.java @@ -12,17 +12,23 @@ import org.fusesource.jansi.Ansi.Attribute; public class ColorPluginAppender extends AbstractAppender { private final Appender oldAppender; + private final ColorConsole plugin; + private final String pluginColor; + private final String reset; - public ColorPluginAppender(Appender oldAppender) { + public ColorPluginAppender(Appender oldAppender, ColorConsole plugin) { super(oldAppender.getName(), null, oldAppender.getLayout()); this.oldAppender = oldAppender; + this.plugin = plugin; + this.reset = Ansi.ansi().a(Attribute.RESET).toString(); + this.pluginColor = format(plugin.getConfig().getString("PLUGIN")); } @Override public void append(LogEvent event) { if (isStarted() && oldAppender.isStarted()) { - Message newMessage = new SimpleMessage(colorizePluginTag(event.getMessage().getFormattedMessage())); + Message newMessage = new SimpleMessage(colorizePluginTag(event.getMessage().getFormattedMessage(), event.getLevel().name())); LogEvent newEvent = new Log4jLogEvent(event.getLoggerName(), event.getMarker(), event.getFQCN() , event.getLevel(), newMessage, event.getThrown(), event.getContextMap() @@ -35,15 +41,47 @@ public class ColorPluginAppender extends AbstractAppender { return oldAppender; } - private String colorizePluginTag(String message) { + private String colorizePluginTag(String message, String level) { if (!message.contains("[") || !message.contains("]")) { return message; } + String levelColor = format(plugin.getConfig().getString(level)); + int start = message.indexOf('[') + 1; int end = message.indexOf(']', start); - String prefix = Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.BLUE).toString(); - String resetSuffix = Ansi.ansi().a(Attribute.RESET).toString(); - return '[' + prefix + message.substring(start, end) + resetSuffix + message.substring(end); + String pluginName = message.substring(start, end); + String thisPluginColor = plugin.getConfig().getString("P-" + pluginName); + if (thisPluginColor != null) { + thisPluginColor = format(thisPluginColor); + } else { + thisPluginColor = pluginColor; + } + return reset + '[' + thisPluginColor + pluginName + reset + ']' + levelColor + message.substring(end + 1); + } + + private String format(String pluginFormat) { + String[] formatParts = pluginFormat.split(" "); + Ansi ansi = Ansi.ansi(); + for (String format : formatParts) { + if (format.equalsIgnoreCase("blink")) { + ansi.a(Attribute.BLINK_SLOW); + continue; + } + if (format.equalsIgnoreCase("bold")) { + ansi.a(Attribute.INTENSITY_BOLD); + continue; + } + if (format.equalsIgnoreCase("underline")) { + ansi.a(Attribute.UNDERLINE); + continue; + } + for (Ansi.Color color : Ansi.Color.values()) { + if (format.equalsIgnoreCase(color.name())) { + ansi.fg(color); + } + } + } + return ansi.toString(); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 84d78ef..4dc7bc6 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -29,3 +29,9 @@ INFO: gray DEBUG: green bold TRACE: blue +#Plugin Colors +PLUGIN: blue +P-Essentials: green +P-WorldEdit: red +P-WorldGuard: cyan +P-Vault: magenta