mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-07 11:20:32 +01:00
DebugLog now extends Logger.
This commit is contained in:
parent
63e0c028d9
commit
1db555581b
@ -11,6 +11,8 @@ import java.io.IOException;
|
|||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.logging.FileHandler;
|
import java.util.logging.FileHandler;
|
||||||
import java.util.logging.Formatter;
|
import java.util.logging.Formatter;
|
||||||
import java.util.logging.Handler;
|
import java.util.logging.Handler;
|
||||||
@ -21,10 +23,9 @@ import java.util.logging.Logger;
|
|||||||
/**
|
/**
|
||||||
* The Multiverse debug-logger.
|
* The Multiverse debug-logger.
|
||||||
*/
|
*/
|
||||||
public class DebugLog {
|
public class DebugLog extends Logger {
|
||||||
|
|
||||||
private FileHandler fh;
|
private FileHandler fh;
|
||||||
private Logger log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new debug logger.
|
* Creates a new debug logger.
|
||||||
@ -33,16 +34,17 @@ public class DebugLog {
|
|||||||
* @param file The file to log to.
|
* @param file The file to log to.
|
||||||
*/
|
*/
|
||||||
public DebugLog(String logger, String file) {
|
public DebugLog(String logger, String file) {
|
||||||
this.log = Logger.getLogger(logger);
|
super(logger, null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.fh = new FileHandler(file, true);
|
this.fh = new FileHandler(file, true);
|
||||||
this.log.setUseParentHandlers(false);
|
this.setUseParentHandlers(false);
|
||||||
for (Handler handler : this.log.getHandlers()) {
|
List<Handler> toRemove = Arrays.asList(this.getHandlers());
|
||||||
this.log.removeHandler(handler);
|
for (Handler handler : toRemove) {
|
||||||
|
this.removeHandler(handler);
|
||||||
}
|
}
|
||||||
this.log.addHandler(this.fh);
|
this.addHandler(this.fh);
|
||||||
this.log.setLevel(Level.ALL);
|
this.setLevel(Level.ALL);
|
||||||
this.fh.setFormatter(new LogFormatter());
|
this.fh.setFormatter(new LogFormatter());
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -51,16 +53,6 @@ public class DebugLog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Log a message at a certain level.
|
|
||||||
*
|
|
||||||
* @param level The log-{@link Level}.
|
|
||||||
* @param msg the message.
|
|
||||||
*/
|
|
||||||
public void log(Level level, String msg) {
|
|
||||||
this.log.log(level, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Our log-{@link Formatter}.
|
* Our log-{@link Formatter}.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user