Added config

This commit is contained in:
games647 2016-05-05 14:57:05 +02:00
parent b3a825a6c9
commit e1e1c60e51
3 changed files with 41 additions and 9 deletions

View File

@ -8,7 +8,7 @@
<packaging>jar</packaging> <packaging>jar</packaging>
<name>ColorConsole</name> <name>ColorConsole</name>
<version>1.1</version> <version>1.2</version>
<inceptionYear>2016</inceptionYear> <inceptionYear>2016</inceptionYear>
<url>http://dev.bukkit.org/bukkit-plugins/colorconsole/</url> <url>http://dev.bukkit.org/bukkit-plugins/colorconsole/</url>
<description> <description>

View File

@ -21,12 +21,16 @@ public class ColorConsole extends JavaPlugin {
@Override @Override
public void onLoad() { public void onLoad() {
saveDefaultConfig();
//try to run it as early as possible //try to run it as early as possible
installLogFormat(); installLogFormat();
} }
@Override @Override
public void onEnable() { public void onEnable() {
saveDefaultConfig();
installLogFormat(); installLogFormat();
} }
@ -55,12 +59,17 @@ public class ColorConsole extends JavaPlugin {
Appender terminalAppender = getTerminalAppender(); Appender terminalAppender = getTerminalAppender();
oldLayout = terminalAppender.getLayout(); oldLayout = terminalAppender.getLayout();
String logFormat = getConfig().getString("logFormat");
if (getConfig().getBoolean("colorLoggingLevel")) {
logFormat = "%highlight{" + logFormat + "}{"
+ "FATAL=red blink, ERROR=red, WARN=yellow bold, INFO=gray, DEBUG=green bold, TRACE=blue}";
}
PatternLayout layout = PatternLayout PatternLayout layout = PatternLayout
.createLayout("%highlight{[%d{HH:mm:ss} %-5level]: %msg%n}{FATAL=red blink, ERROR=red, " .createLayout(logFormat, new DefaultConfiguration(), null, Charset.defaultCharset().name(), "true");
+ "WARN=yellow bold, INFO=gray, DEBUG=green bold, TRACE=blue}", new DefaultConfiguration()
, null, Charset.defaultCharset().name(), "true");
setLayout(layout); setLayout(layout);
if (getConfig().getBoolean("colorPluginTag")) {
Logger rootLogger = ((Logger) LogManager.getRootLogger()); Logger rootLogger = ((Logger) LogManager.getRootLogger());
ColorPluginAppender pluginAppender = new ColorPluginAppender(terminalAppender); ColorPluginAppender pluginAppender = new ColorPluginAppender(terminalAppender);
@ -69,6 +78,7 @@ public class ColorConsole extends JavaPlugin {
rootLogger.removeAppender(terminalAppender); rootLogger.removeAppender(terminalAppender);
rootLogger.addAppender(pluginAppender); rootLogger.addAppender(pluginAppender);
} }
}
private void setLayout(Layout<? extends Serializable> layout) { private void setLayout(Layout<? extends Serializable> layout) {
Appender terminalAppender = getTerminalAppender(); Appender terminalAppender = getTerminalAppender();

View File

@ -0,0 +1,22 @@
# ConsoleColor config
# Should the plugin tag [PLUGIN_NAME] be highlighted
colorPluginTag: true
# Should the log message be highlighted depending on the logging level
colorLoggingLevel: true
# How the messages should be displayed
#
# Variables:
# %thread - Thread name
# %d{HH:mm:ss} - Timestamp
# %msg - log message
# %n - new line
# These variables try to get the orgin. This is an expensive operation and may impact performance. Use with caution.
# %class{precision} - Class name
# %method - Method name
# %line - Line number
#
# For more details vist: https://logging.apache.org/log4j/2.x/manual/layouts.html#Patterns
logFormat: '[%d{HH:mm:ss} %-5level]: %msg%n'