DebugLog: No more duplicates and you can now modify the log-tag.

This commit is contained in:
main() 2012-06-26 17:26:10 +02:00
parent 9eccf93b66
commit a60e4e06e1
1 changed files with 15 additions and 4 deletions

View File

@ -26,9 +26,9 @@ import java.util.logging.Logger;
* The Multiverse debug-logger. * The Multiverse debug-logger.
*/ */
public class DebugLog extends Logger { public class DebugLog extends Logger {
private FileHandler fh; private FileHandler fh;
private Logger standardLog = null; private Logger standardLog = null;
private String prefix = "[MVCore-Debug] ";
/** /**
* Creates a new debug logger. * Creates a new debug logger.
@ -55,6 +55,14 @@ public class DebugLog extends Logger {
} }
} }
/**
* Sets the log-tag.
* @param tag The new tag.
*/
public void setTag(String tag) {
this.prefix = tag + " ";
}
/** /**
* Specifies the logger to use to send debug messages to as the debug logger itself only sends messages to a file. * Specifies the logger to use to send debug messages to as the debug logger itself only sends messages to a file.
* *
@ -70,12 +78,15 @@ public class DebugLog extends Logger {
* @param level The log-{@link Level}. * @param level The log-{@link Level}.
* @param msg the message. * @param msg the message.
*/ */
@Override
public void log(Level level, String msg) { public void log(Level level, String msg) {
if (MultiverseCoreConfiguration.isSet() && MultiverseCoreConfiguration.getInstance().getGlobalDebug() > 0) { if (MultiverseCoreConfiguration.isSet() && MultiverseCoreConfiguration.getInstance().getGlobalDebug() > 0) {
if (standardLog != null) { // only redirect to standardLog if it's lower than INFO so we don't log that twice!
standardLog.log(level, "[MVCore-Debug] " + msg); if ((level.intValue() < Level.INFO.intValue()) && (standardLog != null)) {
standardLog.log(level, prefix + msg);
} }
super.log(level, "[MVCore-Debug] " + msg);
super.log(level, prefix + msg);
} }
} }