Created our own log formatter

This commit is contained in:
Jaime Martínez Rincón 2018-01-05 12:58:16 +01:00
parent e02e77db96
commit e97350114b
4 changed files with 46 additions and 4 deletions

View File

@ -11,7 +11,7 @@
<name>PlayerBalancer Plugin</name> <name>PlayerBalancer Plugin</name>
<artifactId>playerbalancer-plugin</artifactId> <artifactId>playerbalancer-plugin</artifactId>
<version>2.1.4.3</version> <version>2.1.4.4</version>
<build> <build>
<finalName>PlayerBalancer</finalName> <finalName>PlayerBalancer</finalName>

View File

@ -12,10 +12,10 @@ import com.jaimemartz.playerbalancer.manager.PlayerLocker;
import com.jaimemartz.playerbalancer.ping.StatusManager; import com.jaimemartz.playerbalancer.ping.StatusManager;
import com.jaimemartz.playerbalancer.section.SectionManager; import com.jaimemartz.playerbalancer.section.SectionManager;
import com.jaimemartz.playerbalancer.settings.SettingsHolder; import com.jaimemartz.playerbalancer.settings.SettingsHolder;
import com.jaimemartz.playerbalancer.utils.CustomFormatter;
import net.md_5.bungee.api.plugin.Command; import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.log.ConciseFormatter;
import ninja.leaping.configurate.commented.CommentedConfigurationNode; import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.hocon.HoconConfigurationLoader; import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
import ninja.leaping.configurate.loader.ConfigurationLoader; import ninja.leaping.configurate.loader.ConfigurationLoader;
@ -48,7 +48,10 @@ public class PlayerBalancer extends Plugin {
Handler handler = new Handler() { Handler handler = new Handler() {
@Override @Override
public void publish(LogRecord record) { public void publish(LogRecord record) {
logsBuilder.append(getFormatter().format(record)); if (isLoggable(record)) {
String formatted = getFormatter().format(record);
logsBuilder.append(formatted);
}
} }
@Override @Override
@ -62,7 +65,7 @@ public class PlayerBalancer extends Plugin {
} }
}; };
handler.setFormatter(new ConciseFormatter()); handler.setFormatter(new CustomFormatter());
getProxy().getLogger().addHandler(handler); getProxy().getLogger().addHandler(handler);
getProxy().getLogger().setUseParentHandlers(true); getProxy().getLogger().setUseParentHandlers(true);
} }

View File

@ -0,0 +1,10 @@
package com.jaimemartz.playerbalancer.settings.props.features;
import lombok.Data;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
@ConfigSerializable
@Data
public class CustomFindProps {
}

View File

@ -0,0 +1,29 @@
package com.jaimemartz.playerbalancer.utils;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
public class CustomFormatter extends Formatter {
private final DateFormat format = new SimpleDateFormat("HH:mm:ss");
@Override
public String format(LogRecord record) {
StringBuilder builder = new StringBuilder(String.format("[%s %s] %s\n",
format.format(record.getMillis()),
record.getLevel().getName(),
formatMessage(record)
));
if (record.getThrown() != null) {
StringWriter writer = new StringWriter();
record.getThrown().printStackTrace(new PrintWriter(writer));
builder.append(writer);
}
return builder.toString();
}
}