Minor clean up

This commit is contained in:
games647 2017-09-23 13:55:42 +02:00
parent 85629d0c4a
commit 62ec40cc53
No known key found for this signature in database
GPG Key ID: BFC68C8708713A88
14 changed files with 57 additions and 81 deletions

14
.gitignore vendored
View File

@ -3,21 +3,21 @@
/.project /.project
/.settings /.settings
# netbeans # NetBeans
/nbproject */nbproject
nb-configuration.xml nb-configuration.xml
# maven # maven
/target */target
# vim # vim
.*.sw[a-p] .*.sw[a-p]
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml # virtual machine crash logs, see https://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid* hs_err_pid*
# various other potential build files # various other potential build files
/build */build/
/bin /bin
/dist /dist
/manifest.mf /manifest.mf
@ -26,7 +26,7 @@ hs_err_pid*
# Mac filesystem dust # Mac filesystem dust
.DS_Store .DS_Store
# intellij # IntelliJ
*.iml *.iml
*.ipr *.ipr
*.iws *.iws
@ -39,4 +39,4 @@ hs_err_pid*
gradle-app.setting gradle-app.setting
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar !gradle-wrapper.jar

View File

@ -1,6 +1,6 @@
# Use https://travis-ci.org/ for automatic tests # Use https://travis-ci.org/ for automatic testing
# speed up testing http://blog.travis-ci.com/2014-12-17-faster-builds-with-container-based-infrastructure/ # speed up testing https://blog.travis-ci.com/2014-12-17-faster-builds-with-container-based-infrastructure/
sudo: false sudo: false
# This is a java project # This is a java project
@ -8,6 +8,4 @@ language: java
script: mvn compile test script: mvn compile test
# We run on 8+ jdk: [oraclejdk8]
jdk:
- oraclejdk8

View File

@ -1,17 +0,0 @@
# ColorConsole
![colorful log example](https://www.spigotmc.org/attachments/upload_2017-5-25_13-18-54-png.243110/)
## Description
This lightweight plugin to make your console more colorful. It colorize the message depending on the log level. This means that important error messages will be printed in a red color. This gives you and your administrators a better overview about what's happening on your server.
## Features
* Lightweight
* Different colors for different log levels
* Ignores specified log messages
* Custom logFormat
* Colorize plugin tags (customizable)
* Easy to use config
* Supports all versions above 1.8+

26
pom.xml
View File

@ -8,15 +8,18 @@
<packaging>jar</packaging> <packaging>jar</packaging>
<name>ColorConsole</name> <name>ColorConsole</name>
<version>2.3.1</version> <version>2.3.2</version>
<inceptionYear>2016</inceptionYear> <inceptionYear>2016</inceptionYear>
<url>http://dev.bukkit.org/bukkit-plugins/colorconsole/</url> <url>https://dev.bukkit.org/bukkit-plugins/colorconsole/</url>
<description> <description>
Print colorful console messages depending on the logging level Print colorful console messages depending on the logging level
</description> </description>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties> </properties>
<build> <build>
@ -25,24 +28,13 @@
<finalName>${project.name}</finalName> <finalName>${project.name}</finalName>
<plugins> <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version> <version>3.0.0</version>
<configuration> <configuration>
<createDependencyReducedPom>false</createDependencyReducedPom> <createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
<artifactSet> <artifactSet>
<includes> <includes>
<include>org.fusesource.jansi:jansi</include> <include>org.fusesource.jansi:jansi</include>
@ -103,7 +95,7 @@
<!--Sponge-API--> <!--Sponge-API-->
<repository> <repository>
<id>sponge-repo</id> <id>sponge-repo</id>
<url>http://repo.spongepowered.org/maven</url> <url>https://repo.spongepowered.org/maven</url>
</repository> </repository>
</repositories> </repositories>
@ -112,7 +104,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.12-R0.1-SNAPSHOT</version> <version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
@ -127,7 +119,7 @@
<dependency> <dependency>
<groupId>org.spongepowered</groupId> <groupId>org.spongepowered</groupId>
<artifactId>spongeapi</artifactId> <artifactId>spongeapi</artifactId>
<version>7.0.0-SNAPSHOT</version> <version>6.0.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@ -16,7 +16,7 @@ import org.bukkit.plugin.java.JavaPlugin;
public class ColorConsoleBukkit extends JavaPlugin { public class ColorConsoleBukkit extends JavaPlugin {
private static String TERMINAL_NAME = "TerminalConsole"; private static final String TERMINAL_NAME = "TerminalConsole";
private Layout<? extends Serializable> oldLayout; private Layout<? extends Serializable> oldLayout;
@ -82,11 +82,11 @@ public class ColorConsoleBukkit extends JavaPlugin {
+ "WARN=" + getConfig().getString("WARN") + ", " + "WARN=" + getConfig().getString("WARN") + ", "
+ "INFO=" + getConfig().getString("INFO") + ", " + "INFO=" + getConfig().getString("INFO") + ", "
+ "DEBUG=" + getConfig().getString("DEBUG") + ", " + "DEBUG=" + getConfig().getString("DEBUG") + ", "
+ "TRACE=" + getConfig().getString("TRACE") + "}"); + "TRACE=" + getConfig().getString("TRACE") + '}');
} }
String dateStyle = getConfig().getString("dateStyle"); String dateStyle = getConfig().getString("dateStyle");
logFormat = logFormat.replaceFirst("(%d)\\{.{1,}\\}", "%style{$0}{" + dateStyle + "}"); logFormat = logFormat.replaceFirst("(%d)\\{.{1,}\\}", "%style{$0}{" + dateStyle + '}');
try { try {
PatternLayout layout = CommonLogInstaller.createLayout(logFormat); PatternLayout layout = CommonLogInstaller.createLayout(logFormat);
CommonLogInstaller.setLayout(layout, terminalAppender); CommonLogInstaller.setLayout(layout, terminalAppender);

View File

@ -14,6 +14,7 @@ import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.message.SimpleMessage; import org.apache.logging.log4j.message.SimpleMessage;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin;
public class ColorPluginAppender extends ColorAppender { public class ColorPluginAppender extends ColorAppender {
@ -35,7 +36,7 @@ public class ColorPluginAppender extends ColorAppender {
@Override @Override
protected Collection<String> loadPluginNames() { protected Collection<String> loadPluginNames() {
return Stream.of(Bukkit.getPluginManager().getPlugins()) return Stream.of(Bukkit.getPluginManager().getPlugins())
.map(plugin -> plugin.getName()) .map(Plugin::getName)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
} }

View File

@ -26,8 +26,8 @@ public abstract class ColorAppender extends AbstractAppender {
for (Method method : LogEvent.class.getDeclaredMethods()) { for (Method method : LogEvent.class.getDeclaredMethods()) {
String methodName = method.getName(); String methodName = method.getName();
if (methodName.equalsIgnoreCase("getLoggerFqcn") if ("getLoggerFqcn".equalsIgnoreCase(methodName)
|| methodName.equalsIgnoreCase("getFQCN")) { || "getFQCN".equalsIgnoreCase(methodName)) {
loggerClassGetter = method; loggerClassGetter = method;
method.setAccessible(true); method.setAccessible(true);
} }

View File

@ -26,7 +26,7 @@ public class CommonFormatter {
private final boolean colorizeTag; private final boolean colorizeTag;
private final boolean truncateColor; private final boolean truncateColor;
private Map<String, String> pluginColors; private Map<String, String> pluginColors;
private Map<String, String> levelColors; private final Map<String, String> levelColors;
public CommonFormatter(Collection<String> ignoreMessages, boolean colorizeTag, boolean truncateColor public CommonFormatter(Collection<String> ignoreMessages, boolean colorizeTag, boolean truncateColor
, Map<String, String> levelColors) { , Map<String, String> levelColors) {
@ -37,7 +37,7 @@ public class CommonFormatter {
Builder<String, String> builder = ImmutableMap.builder(); Builder<String, String> builder = ImmutableMap.builder();
for (Map.Entry<String, String> entry : levelColors.entrySet()) { for (Map.Entry<String, String> entry : levelColors.entrySet()) {
if (entry.getKey().equals("INFO")) { if ("INFO".equals(entry.getKey())) {
continue; continue;
} }
@ -61,7 +61,7 @@ public class CommonFormatter {
return false; return false;
} }
public void initPluginColors(Collection<String> plugins, Map<String, String> configColors, String def) { public void initPluginColors(Iterable<String> plugins, Map<String, String> configColors, String def) {
Random random = new Random(); Random random = new Random();
Color[] colors = Color.values(); Color[] colors = Color.values();
//remove black, because it's often hard to read //remove black, because it's often hard to read
@ -70,7 +70,7 @@ public class CommonFormatter {
ImmutableMap.Builder<String, String> colorBuilder = ImmutableMap.builder(); ImmutableMap.Builder<String, String> colorBuilder = ImmutableMap.builder();
for (String plugin : plugins) { for (String plugin : plugins) {
String styleCode = configColors.getOrDefault(plugin, def); String styleCode = configColors.getOrDefault(plugin, def);
if (styleCode.equalsIgnoreCase("random")) { if ("random".equalsIgnoreCase(styleCode)) {
//ignore default //ignore default
styleCode = colors[random.nextInt(colors.length - 1)].name(); styleCode = colors[random.nextInt(colors.length - 1)].name();
} }

View File

@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -26,47 +27,47 @@ public class ColorConsoleConfig {
} }
@Setting(comment = "Should the plugin tag [PLUGIN_NAME] be highlighted") @Setting(comment = "Should the plugin tag [PLUGIN_NAME] be highlighted")
private boolean colorPluginTag = true; private final boolean colorPluginTag = true;
@Setting(comment = "Should the log message be highlighted depending on the logging level") @Setting(comment = "Should the log message be highlighted depending on the logging level")
private boolean colorLoggingLevel = true; private final boolean colorLoggingLevel = true;
@Setting(comment = "How the messages should be displayed\n" @Setting(comment = "How the messages should be displayed\n"
+ "\n" + '\n'
+ "Variables:\n" + "Variables:\n"
+ "%thread - Thread name\n" + "%thread - Thread name\n"
+ "%d{HH:mm:ss} - Timestamp\n" + "%d{HH:mm:ss} - Timestamp\n"
+ "%msg - log message\n" + "%msg - log message\n"
+ "%logger - logger name\n" + "%logger - logger name\n"
+ "%n - new line\n" + "%n - new line\n"
+ "\n" + '\n'
+ "These variables try to get the orgin. This is an expensive operation and may impact performance. " + "These variables try to get the origin. This is an expensive operation and may impact performance. "
+ "Use with caution.\n" + "Use with caution.\n"
+ "\n" + '\n'
+ "%class{precision} - Class name\n" + "%class{precision} - Class name\n"
+ "%method - Method name\n" + "%method - Method name\n"
+ "%line - Line number\n" + "%line - Line number\n"
+ "\n" + '\n'
+ "For more details vist: https://logging.apache.org/log4j/2.x/manual/layouts.html#Patterns") + "For more details visit: https://logging.apache.org/log4j/2.x/manual/layouts.html#Patterns")
private String logFormat = "[%d{HH:mm:ss} %level] [%logger{1}]: %msg%n"; private final String logFormat = "[%d{HH:mm:ss} %level] [%logger{1}]: %msg%n";
@Setting(comment = "Log Level Colors") @Setting(comment = "Log Level Colors")
private Map<String, String> levelColors; private final Map<String, String> levelColors;
@Setting(comment = "Plugin Colors or random") @Setting(comment = "Plugin Colors or random")
private String defaultPluginColor = "blue"; private final String defaultPluginColor = "blue";
@Setting(comment = "Custom plugin colors") @Setting(comment = "Custom plugin colors")
private Map<String, String> pluginColors; private final Map<String, String> pluginColors;
@Setting(comment = "How should the time be highlighted\n" + @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 " + "Like below it could also be default which means it's the default font color depending on " +
"your terminal settings.") "your terminal settings.")
private String dateStyle = "cyan"; private final String dateStyle = "cyan";
@Setting(comment = "Hides the log message if it contains one or more of the following texts\n" @Setting(comment = "Hides the log message if it contains one or more of the following texts\n"
+ "The texts are case-sensitive") + "The texts are case-sensitive")
private List<String> hideMessages = Lists.newArrayList(); private final List<String> hideMessages = Lists.newArrayList();
@Setting(comment = "Removes color formatting if the complete message has color formatting") @Setting(comment = "Removes color formatting if the complete message has color formatting")
private boolean truncateColor; private boolean truncateColor;
@ -100,7 +101,7 @@ public class ColorConsoleConfig {
return pluginColors; return pluginColors;
} }
public Set<String> getHideMessages() { public Collection<String> getHideMessages() {
return ImmutableSet.copyOf(hideMessages); return ImmutableSet.copyOf(hideMessages);
} }

View File

@ -28,7 +28,7 @@ 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 = "Console";
private static String TERMINAL_NAME = "MinecraftConsole"; private static final String TERMINAL_NAME = "MinecraftConsole";
private final Logger logger; private final Logger logger;
@ -93,11 +93,11 @@ public class ColorConsoleSponge {
+ "WARN=" + configMapper.getInstance().getLevelColors().get("WARN") + ", " + "WARN=" + configMapper.getInstance().getLevelColors().get("WARN") + ", "
+ "INFO=" + configMapper.getInstance().getLevelColors().get("INFO") + ", " + "INFO=" + configMapper.getInstance().getLevelColors().get("INFO") + ", "
+ "DEBUG=" + configMapper.getInstance().getLevelColors().get("DEBUG") + ", " + "DEBUG=" + configMapper.getInstance().getLevelColors().get("DEBUG") + ", "
+ "TRACE=" + configMapper.getInstance().getLevelColors().get("TRACE") + "}"); + "TRACE=" + configMapper.getInstance().getLevelColors().get("TRACE") + '}');
} }
String dateStyle = configMapper.getInstance().getDateStyle(); String dateStyle = configMapper.getInstance().getDateStyle();
logFormat = logFormat.replace("%d{HH:mm:ss}", "%style{" + "%d{HH:mm:ss}" + "}{" + dateStyle + "}"); logFormat = logFormat.replace("%d{HH:mm:ss}", "%style{" + "%d{HH:mm:ss}" + "}{" + dateStyle + '}');
try { try {
PatternLayout layout = CommonLogInstaller.createLayout(logFormat); PatternLayout layout = CommonLogInstaller.createLayout(logFormat);

View File

@ -9,6 +9,7 @@ import java.util.stream.Collectors;
import org.apache.logging.log4j.core.Appender; import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.LogEvent;
import org.spongepowered.api.Sponge; import org.spongepowered.api.Sponge;
import org.spongepowered.api.plugin.PluginContainer;
public class ColorPluginAppender extends ColorAppender { public class ColorPluginAppender extends ColorAppender {
@ -26,7 +27,7 @@ public class ColorPluginAppender extends ColorAppender {
@Override @Override
protected Collection<String> loadPluginNames() { protected Collection<String> loadPluginNames() {
return Sponge.getPluginManager().getPlugins().stream() return Sponge.getPluginManager().getPlugins().stream()
.map(pluginContainer -> pluginContainer.getId()) .map(PluginContainer::getId)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
} }

View File

@ -6,7 +6,7 @@ name: ${project.name}
main: ${project.groupId}.${project.artifactId}.bungee.${project.name}Bungee main: ${project.groupId}.${project.artifactId}.bungee.${project.name}Bungee
version: ${project.version} version: ${project.version}
author: games647, http://github.com/games647/ColorConsole/graphs/contributors author: games647, https://github.com/games647/ColorConsole/graphs/contributors
description: | description: |
${project.description} ${project.description}

View File

@ -17,12 +17,12 @@ colorMessage: false
# %d{HH:mm:ss} - Timestamp # %d{HH:mm:ss} - Timestamp
# %msg - log message # %msg - log message
# %n - new line # %n - new line
# These variables try to get the orgin. This is an expensive operation and may impact performance. Use with caution. # These variables try to get the origin. This is an expensive operation and may impact performance. Use with caution.
# %class{precision} - Class name # %class{precision} - Class name
# %method - Method name # %method - Method name
# %line - Line number # %line - Line number
# #
# For more details vist: https://logging.apache.org/log4j/2.x/manual/layouts.html#Patterns # For more details visit: https://logging.apache.org/log4j/2.x/manual/layouts.html#Patterns
logFormat: '[%d{HH:mm:ss} %level]: %msg%n' logFormat: '[%d{HH:mm:ss} %level]: %msg%n'
# Log Level Colors # Log Level Colors

View File

@ -1,10 +1,10 @@
# project informations for Bukkit in order to register our plugin with all it components # project data for Bukkit in order to register our plugin with all it components
# ${-} are variables from Maven (pom.xml) which will be replaced after the build # ${-} are variables from Maven (pom.xml) which will be replaced after the build
name: ${project.name} name: ${project.name}
version: ${project.version} version: ${project.version}
main: ${project.groupId}.${project.artifactId}.bukkit.${project.name}Bukkit main: ${project.groupId}.${project.artifactId}.bukkit.${project.name}Bukkit
# meta informations for plugin managers # meta data for plugin managers
authors: [games647, 'https://github.com/games647/ColorConsole/graphs/contributors'] authors: [games647, 'https://github.com/games647/ColorConsole/graphs/contributors']
description: | description: |
${project.description} ${project.description}