mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-04 05:54:43 +01:00
Added command line option 'date-format' to control how dates are printed to console (not to log)
This commit is contained in:
parent
bb8d9fbe9d
commit
07b86b1230
4 changed files with 40 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
||||||
package net.minecraft.server;
|
package net.minecraft.server;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.logging.ConsoleHandler;
|
import java.util.logging.ConsoleHandler;
|
||||||
import java.util.logging.FileHandler;
|
import java.util.logging.FileHandler;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
@ -18,11 +19,11 @@ public class ConsoleLogManager {
|
||||||
public ConsoleLogManager() {}
|
public ConsoleLogManager() {}
|
||||||
|
|
||||||
// Craftbukkit - change of method signature!
|
// Craftbukkit - change of method signature!
|
||||||
public static void a(ConsoleReader reader) {
|
public static void a(MinecraftServer server) {
|
||||||
ConsoleLogFormatter consolelogformatter = new ConsoleLogFormatter();
|
ConsoleLogFormatter consolelogformatter = new ConsoleLogFormatter();
|
||||||
|
|
||||||
a.setUseParentHandlers(false);
|
a.setUseParentHandlers(false);
|
||||||
ConsoleHandler consolehandler = new TerminalConsoleHandler(reader);
|
ConsoleHandler consolehandler = new TerminalConsoleHandler(server.reader); // Craftbukkit
|
||||||
|
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
for (Handler handler: global.getHandlers()) {
|
for (Handler handler: global.getHandlers()) {
|
||||||
|
@ -30,7 +31,7 @@ public class ConsoleLogManager {
|
||||||
}
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
consolehandler.setFormatter(new ShortConsoleLogFormatter()); // Craftbukkit
|
consolehandler.setFormatter(new ShortConsoleLogFormatter(server)); // Craftbukkit
|
||||||
a.addHandler(consolehandler);
|
a.addHandler(consolehandler);
|
||||||
global.addHandler(consolehandler); // CraftBukkit
|
global.addHandler(consolehandler); // CraftBukkit
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class MinecraftServer implements Runnable, ICommandListener {
|
||||||
|
|
||||||
threadcommandreader.setDaemon(true);
|
threadcommandreader.setDaemon(true);
|
||||||
threadcommandreader.start();
|
threadcommandreader.start();
|
||||||
ConsoleLogManager.a(reader); // Craftbukkit
|
ConsoleLogManager.a(this); // Craftbukkit
|
||||||
|
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
System.setOut(new PrintStream(new LoggerOutputStream(a, Level.INFO), true));
|
System.setOut(new PrintStream(new LoggerOutputStream(a, Level.INFO), true));
|
||||||
|
|
|
@ -2,6 +2,9 @@ package org.bukkit.craftbukkit;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.Format;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
@ -53,6 +56,11 @@ public class Main {
|
||||||
.withRequiredArg()
|
.withRequiredArg()
|
||||||
.ofType(Integer.class)
|
.ofType(Integer.class)
|
||||||
.describedAs("Server size");
|
.describedAs("Server size");
|
||||||
|
|
||||||
|
acceptsAll(asList("d", "date-format"), "Format of the date to display in the console (for log entries)")
|
||||||
|
.withRequiredArg()
|
||||||
|
.ofType(SimpleDateFormat.class)
|
||||||
|
.describedAs("Log date format");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,35 @@ import java.io.StringWriter;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.logging.Formatter;
|
import java.util.logging.Formatter;
|
||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
|
import joptsimple.OptionException;
|
||||||
|
import joptsimple.OptionSet;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
|
||||||
public class ShortConsoleLogFormatter extends Formatter {
|
public class ShortConsoleLogFormatter extends Formatter {
|
||||||
private final SimpleDateFormat date = new SimpleDateFormat("HH:mm:ss");
|
private final SimpleDateFormat date;
|
||||||
|
|
||||||
|
public ShortConsoleLogFormatter(MinecraftServer server) {
|
||||||
|
OptionSet options = server.options;
|
||||||
|
SimpleDateFormat date = null;
|
||||||
|
|
||||||
|
if (options.has("date-format")) {
|
||||||
|
try {
|
||||||
|
Object object = options.valueOf("date-format");
|
||||||
|
|
||||||
|
if ((object != null) && (object instanceof SimpleDateFormat)) {
|
||||||
|
date = (SimpleDateFormat)object;
|
||||||
|
}
|
||||||
|
} catch (OptionException ex) {
|
||||||
|
System.err.println("Given date format is not valid. Falling back to default.");
|
||||||
|
} finally {
|
||||||
|
if (date == null) {
|
||||||
|
date = new SimpleDateFormat("HH:mm:ss");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String format(LogRecord record) {
|
public String format(LogRecord record) {
|
||||||
|
|
Loading…
Reference in a new issue