mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-26 20:55:42 +01:00
Created our own log formatter
This commit is contained in:
parent
e02e77db96
commit
e97350114b
@ -11,7 +11,7 @@
|
||||
|
||||
<name>PlayerBalancer Plugin</name>
|
||||
<artifactId>playerbalancer-plugin</artifactId>
|
||||
<version>2.1.4.3</version>
|
||||
<version>2.1.4.4</version>
|
||||
|
||||
<build>
|
||||
<finalName>PlayerBalancer</finalName>
|
||||
|
@ -12,10 +12,10 @@ import com.jaimemartz.playerbalancer.manager.PlayerLocker;
|
||||
import com.jaimemartz.playerbalancer.ping.StatusManager;
|
||||
import com.jaimemartz.playerbalancer.section.SectionManager;
|
||||
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.Listener;
|
||||
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.hocon.HoconConfigurationLoader;
|
||||
import ninja.leaping.configurate.loader.ConfigurationLoader;
|
||||
@ -48,7 +48,10 @@ public class PlayerBalancer extends Plugin {
|
||||
Handler handler = new Handler() {
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
logsBuilder.append(getFormatter().format(record));
|
||||
if (isLoggable(record)) {
|
||||
String formatted = getFormatter().format(record);
|
||||
logsBuilder.append(formatted);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -62,7 +65,7 @@ public class PlayerBalancer extends Plugin {
|
||||
}
|
||||
};
|
||||
|
||||
handler.setFormatter(new ConciseFormatter());
|
||||
handler.setFormatter(new CustomFormatter());
|
||||
getProxy().getLogger().addHandler(handler);
|
||||
getProxy().getLogger().setUseParentHandlers(true);
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user