Do not override content if it's not starting with an plugin name
This commit is contained in:
parent
6eeb94a5c2
commit
acd9da4cd2
4
pom.xml
4
pom.xml
|
@ -134,7 +134,7 @@
|
|||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12-pre2-SNAPSHOT</version>
|
||||
<version>1.12-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -149,7 +149,7 @@
|
|||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>spongeapi</artifactId>
|
||||
<version>6.1.0-20170502.022019-1</version>
|
||||
<version>7.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
|
|
@ -70,12 +70,11 @@ public class ColorConsoleBukkit extends JavaPlugin {
|
|||
Appender terminalAppender = CommonLogInstaller.getTerminalAppender(TERMINAL_NAME);
|
||||
|
||||
oldLayout = terminalAppender.getLayout();
|
||||
String logFormat = oldLayout.toString();
|
||||
if (oldLayout.toString().contains("%minecraftFormatting")) {
|
||||
logFormat.replace("%msg", "%minecraftFormatting{%msg}");
|
||||
String logFormat = getConfig().getString("logFormat");
|
||||
if (oldLayout.toString().contains("minecraftFormatting")) {
|
||||
logFormat = logFormat.replace("%msg", "%minecraftFormatting{%msg}");
|
||||
}
|
||||
|
||||
logFormat = "[%d{HH:mm:ss} %level]: %minecraftFormatting{%msg}%n%xEx";
|
||||
if (getConfig().getBoolean("colorLoggingLevel")) {
|
||||
logFormat = logFormat.replace("%level", "%highlight{%level}{"
|
||||
+ "FATAL=" + getConfig().getString("FATAL") + ", "
|
||||
|
|
|
@ -98,6 +98,10 @@ public class CommonFormatter {
|
|||
}
|
||||
}
|
||||
|
||||
if (!newMessage.startsWith("[")) {
|
||||
return levelColors.getOrDefault(level, "") + message + reset;
|
||||
}
|
||||
|
||||
int startTag = newMessage.indexOf('[') + 1;
|
||||
int endTag = newMessage.indexOf(']', startTag);
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package com.github.games647.colorconsole.sponge;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -17,7 +20,7 @@ public class ColorConsoleConfig {
|
|||
this.levelColors.put("FATAL", "red blink");
|
||||
this.levelColors.put("ERROR", "red");
|
||||
this.levelColors.put("WARN", "yellow bold");
|
||||
this.levelColors.put("INFO", "default");
|
||||
this.levelColors.put("INFO", "green");
|
||||
this.levelColors.put("DEBUG", "green bold");
|
||||
this.levelColors.put("TRACE", "blue");
|
||||
}
|
||||
|
@ -45,7 +48,7 @@ public class ColorConsoleConfig {
|
|||
+ "%line - Line number\n"
|
||||
+ "\n"
|
||||
+ "For more details vist: https://logging.apache.org/log4j/2.x/manual/layouts.html#Patterns")
|
||||
private String logFormat = "[%d{HH:mm:ss}] [%level] [%logger]: %msg%n";
|
||||
private String logFormat = "[%d{HH:mm:ss} %level] [%logger{1}]: %msg%n";
|
||||
|
||||
@Setting(comment = "Log Level Colors")
|
||||
private Map<String, String> levelColors;
|
||||
|
@ -59,11 +62,11 @@ public class ColorConsoleConfig {
|
|||
@Setting(comment = "How should the time be highlighted\n" +
|
||||
"Like below it could also be default which means it's the default font color depending on " +
|
||||
"your terminal settings.")
|
||||
private String dateStyle;
|
||||
private String dateStyle = "cyan";
|
||||
|
||||
@Setting(comment = "Hides the log message if it contains one or more of the following texts\n"
|
||||
+ "The texts are case-sensitive")
|
||||
private Set<String> hideMessages;
|
||||
private List<String> hideMessages = Lists.newArrayList();
|
||||
|
||||
@Setting(comment = "Removes color formatting if the complete message has color formatting")
|
||||
private boolean truncateColor;
|
||||
|
@ -98,7 +101,7 @@ public class ColorConsoleConfig {
|
|||
}
|
||||
|
||||
public Set<String> getHideMessages() {
|
||||
return hideMessages;
|
||||
return ImmutableSet.copyOf(hideMessages);
|
||||
}
|
||||
|
||||
public String getDateStyle() {
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.github.games647.colorconsole.common.CommonLogInstaller;
|
|||
import com.google.inject.Inject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
||||
|
@ -11,8 +12,8 @@ import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
|
|||
import ninja.leaping.configurate.loader.ConfigurationLoader;
|
||||
import ninja.leaping.configurate.objectmapping.ObjectMapper;
|
||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||
|
||||
import org.apache.logging.log4j.core.Appender;
|
||||
import org.apache.logging.log4j.core.Layout;
|
||||
import org.apache.logging.log4j.core.layout.PatternLayout;
|
||||
import org.slf4j.Logger;
|
||||
import org.spongepowered.api.config.DefaultConfig;
|
||||
|
@ -20,12 +21,14 @@ import org.spongepowered.api.event.Listener;
|
|||
import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
|
||||
import org.spongepowered.api.plugin.Plugin;
|
||||
|
||||
@Plugin(id = "colorconsole", name = "ColorConsole", version = "2.2"
|
||||
@Plugin(id = "colorconsole", name = "ColorConsole", version = "2.3"
|
||||
, url = "https://github.com/games647/ColorConsole/"
|
||||
, description = "Print colorful console messages depending on the logging level")
|
||||
public class ColorConsoleSponge {
|
||||
|
||||
private static String TERMINAL_NAME = "FmlConsole";
|
||||
// private static String TERMINAL_NAME = "FmlConsole";
|
||||
// private static String TERMINAL_NAME = "Console";
|
||||
private static String TERMINAL_NAME = "MinecraftConsole";
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
|
@ -72,13 +75,17 @@ public class ColorConsoleSponge {
|
|||
}
|
||||
|
||||
installLogFormat();
|
||||
logger.warn("Test");
|
||||
}
|
||||
|
||||
private void installLogFormat() {
|
||||
Appender terminalAppender = CommonLogInstaller.getTerminalAppender(TERMINAL_NAME);
|
||||
|
||||
|
||||
Layout<? extends Serializable> oldLayout = terminalAppender.getLayout();
|
||||
String logFormat = configMapper.getInstance().getLogFormat();
|
||||
if (oldLayout.toString().contains("%minecraftFormatting")) {
|
||||
logFormat = logFormat.replace("%msg", "%minecraftFormatting{%msg}");
|
||||
}
|
||||
|
||||
if (configMapper.getInstance().isColorLoggingLevel()) {
|
||||
logFormat = logFormat.replace("%level", "%highlight{%level}{"
|
||||
+ "FATAL=" + configMapper.getInstance().getLevelColors().get("FATAL") + ", "
|
||||
|
@ -90,7 +97,7 @@ public class ColorConsoleSponge {
|
|||
}
|
||||
|
||||
String dateStyle = configMapper.getInstance().getDateStyle();
|
||||
logFormat = logFormat.replaceFirst("(%d)\\{.{1,}\\}", "%style{$0}{" + dateStyle + "}");
|
||||
logFormat = logFormat.replace("%d{HH:mm:ss}", "%style{" + "%d{HH:mm:ss}" + "}{" + dateStyle + "}");
|
||||
|
||||
try {
|
||||
PatternLayout layout = CommonLogInstaller.createLayout(logFormat);
|
||||
|
@ -103,5 +110,6 @@ public class ColorConsoleSponge {
|
|||
pluginAppender.initPluginColors(getConfig().getPluginColors(), getConfig().getDefaultPluginColor());
|
||||
|
||||
CommonLogInstaller.installAppender(pluginAppender, TERMINAL_NAME);
|
||||
CommonLogInstaller.installAppender(pluginAppender, "Console");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue