2011-02-20 03:14:15 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.logging.ConsoleHandler;
|
|
|
|
import java.util.logging.FileHandler;
|
2013-03-13 23:33:27 +01:00
|
|
|
import java.util.logging.Handler;
|
2011-02-20 03:14:15 +01:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
2012-07-22 08:18:00 +02:00
|
|
|
import java.io.File; // CraftBukkit
|
2011-02-23 13:56:36 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public class ConsoleLogManager implements IConsoleLogManager {
|
2011-02-20 03:14:15 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
private final Logger a;
|
|
|
|
private final String b;
|
|
|
|
private final String c;
|
|
|
|
private final String d;
|
2011-02-23 13:56:36 +01:00
|
|
|
public static Logger global = Logger.getLogger(""); // CraftBukkit
|
2011-02-20 03:14:15 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public ConsoleLogManager(String s, String s1, String s2) {
|
|
|
|
this.a = Logger.getLogger(s);
|
|
|
|
this.c = s;
|
|
|
|
this.d = s1;
|
|
|
|
this.b = s2;
|
|
|
|
this.b();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void b() {
|
|
|
|
this.a.setUseParentHandlers(false);
|
|
|
|
Handler[] ahandler = this.a.getHandlers();
|
|
|
|
int i = ahandler.length;
|
|
|
|
|
|
|
|
for (int j = 0; j < i; ++j) {
|
|
|
|
Handler handler = ahandler[j];
|
|
|
|
|
|
|
|
this.a.removeHandler(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
ConsoleLogFormatter consolelogformatter = new ConsoleLogFormatter(this, (EmptyClass3) null);
|
2011-02-20 03:14:15 +01:00
|
|
|
|
2011-02-23 13:56:36 +01:00
|
|
|
// CraftBukkit start
|
2013-03-13 23:33:27 +01:00
|
|
|
MinecraftServer server = MinecraftServer.getServer();
|
2012-07-22 08:18:00 +02:00
|
|
|
ConsoleHandler consolehandler = new org.bukkit.craftbukkit.util.TerminalConsoleHandler(server.reader);
|
2013-03-13 23:33:27 +01:00
|
|
|
// CraftBukkit end
|
2011-03-31 22:40:00 +02:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
consolehandler.setFormatter(consolelogformatter);
|
|
|
|
this.a.addHandler(consolehandler);
|
|
|
|
|
|
|
|
// CraftBukkit start
|
2012-07-22 08:18:00 +02:00
|
|
|
for (java.util.logging.Handler handler : global.getHandlers()) {
|
2011-02-20 03:14:15 +01:00
|
|
|
global.removeHandler(handler);
|
|
|
|
}
|
|
|
|
|
2012-07-22 08:18:00 +02:00
|
|
|
consolehandler.setFormatter(new org.bukkit.craftbukkit.util.ShortConsoleLogFormatter(server));
|
2011-03-31 22:40:00 +02:00
|
|
|
global.addHandler(consolehandler);
|
|
|
|
// CraftBukkit end
|
2011-04-20 19:05:14 +02:00
|
|
|
|
2011-02-20 03:14:15 +01:00
|
|
|
try {
|
2011-07-10 19:28:57 +02:00
|
|
|
// CraftBukkit start
|
2012-01-14 23:02:10 +01:00
|
|
|
String pattern = (String) server.options.valueOf("log-pattern");
|
2012-04-24 23:30:14 +02:00
|
|
|
|
|
|
|
// We have to parse the pattern ourself so we can create directories as needed (java #6244047)
|
|
|
|
String tmpDir = System.getProperty("java.io.tmpdir");
|
|
|
|
String homeDir = System.getProperty("user.home");
|
|
|
|
if (tmpDir == null) {
|
|
|
|
tmpDir = homeDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We only care about parsing for directories, FileHandler can do file names by itself
|
|
|
|
File parent = new File(pattern).getParentFile();
|
|
|
|
StringBuilder fixedPattern = new StringBuilder();
|
2012-06-06 19:12:42 +02:00
|
|
|
String parentPath = "";
|
|
|
|
if (parent != null) {
|
|
|
|
parentPath = parent.getPath();
|
|
|
|
}
|
2012-04-24 23:30:14 +02:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
int j = 0;
|
|
|
|
while (j < parentPath.length()) {
|
|
|
|
char ch = parentPath.charAt(j);
|
2012-04-24 23:30:14 +02:00
|
|
|
char ch2 = 0;
|
2013-03-13 23:33:27 +01:00
|
|
|
if (j + 1 < parentPath.length()) {
|
|
|
|
ch2 = Character.toLowerCase(pattern.charAt(j + 1));
|
2012-04-24 23:30:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ch == '%') {
|
|
|
|
if (ch2 == 'h') {
|
2013-03-13 23:33:27 +01:00
|
|
|
j += 2;
|
2012-04-24 23:30:14 +02:00
|
|
|
fixedPattern.append(homeDir);
|
|
|
|
continue;
|
|
|
|
} else if (ch2 == 't') {
|
2013-03-13 23:33:27 +01:00
|
|
|
j += 2;
|
2012-04-24 23:30:14 +02:00
|
|
|
fixedPattern.append(tmpDir);
|
|
|
|
continue;
|
|
|
|
} else if (ch2 == '%') {
|
|
|
|
// Even though we don't care about this we have to skip it to avoid matching %%t
|
2013-03-13 23:33:27 +01:00
|
|
|
j += 2;
|
2012-04-24 23:30:14 +02:00
|
|
|
fixedPattern.append("%%");
|
|
|
|
continue;
|
|
|
|
} else if (ch2 != 0) {
|
|
|
|
throw new java.io.IOException("log-pattern can only use %t and %h for directories, got %" + ch2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fixedPattern.append(ch);
|
2013-03-13 23:33:27 +01:00
|
|
|
j++;
|
2012-04-24 23:30:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Try to create needed parent directories
|
|
|
|
parent = new File(fixedPattern.toString());
|
|
|
|
if (parent != null) {
|
|
|
|
parent.mkdirs();
|
|
|
|
}
|
|
|
|
|
2012-09-10 06:19:28 +02:00
|
|
|
int limit = (Integer) server.options.valueOf("log-limit");
|
|
|
|
int count = (Integer) server.options.valueOf("log-count");
|
|
|
|
boolean append = (Boolean) server.options.valueOf("log-append");
|
2011-07-10 19:28:57 +02:00
|
|
|
FileHandler filehandler = new FileHandler(pattern, limit, count, append);
|
2012-01-12 19:43:34 +01:00
|
|
|
// CraftBukkit end
|
2011-02-20 03:14:15 +01:00
|
|
|
|
|
|
|
filehandler.setFormatter(consolelogformatter);
|
2013-03-13 23:33:27 +01:00
|
|
|
this.a.addHandler(filehandler);
|
2011-02-23 13:56:36 +01:00
|
|
|
global.addHandler(filehandler); // CraftBukkit
|
2011-02-20 03:14:15 +01:00
|
|
|
} catch (Exception exception) {
|
2013-03-13 23:33:27 +01:00
|
|
|
this.a.log(Level.WARNING, "Failed to log " + this.c + " to " + this.b, exception);
|
2011-02-20 03:14:15 +01:00
|
|
|
}
|
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
|
|
|
|
public Logger getLogger() {
|
|
|
|
return this.a;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void info(String s) {
|
|
|
|
this.a.log(Level.INFO, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void warning(String s) {
|
|
|
|
this.a.log(Level.WARNING, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void warning(String s, Object... aobject) {
|
|
|
|
this.a.log(Level.WARNING, s, aobject);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void warning(String s, Throwable throwable) {
|
|
|
|
this.a.log(Level.WARNING, s, throwable);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void severe(String s) {
|
|
|
|
this.a.log(Level.SEVERE, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void severe(String s, Throwable throwable) {
|
|
|
|
this.a.log(Level.SEVERE, s, throwable);
|
|
|
|
}
|
|
|
|
|
|
|
|
static String a(ConsoleLogManager consolelogmanager) {
|
|
|
|
return consolelogmanager.d;
|
|
|
|
}
|
2011-02-23 13:56:36 +01:00
|
|
|
}
|