summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/logging
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/logging')
-rw-r--r--src/de/lmu/ifi/dbs/elki/logging/CLISmartHandler.java4
-rw-r--r--src/de/lmu/ifi/dbs/elki/logging/ELKILogRecord.java4
-rw-r--r--src/de/lmu/ifi/dbs/elki/logging/ErrorFormatter.java58
-rw-r--r--src/de/lmu/ifi/dbs/elki/logging/Logging.java41
-rw-r--r--src/de/lmu/ifi/dbs/elki/logging/LoggingConfiguration.java6
-rw-r--r--src/de/lmu/ifi/dbs/elki/logging/LoggingUtil.java18
-rw-r--r--src/de/lmu/ifi/dbs/elki/logging/progress/AbstractProgress.java4
-rw-r--r--src/de/lmu/ifi/dbs/elki/logging/progress/FiniteProgress.java18
-rw-r--r--src/de/lmu/ifi/dbs/elki/logging/progress/IndefiniteProgress.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/logging/progress/Progress.java7
-rw-r--r--src/de/lmu/ifi/dbs/elki/logging/progress/ProgressTracker.java3
-rw-r--r--src/de/lmu/ifi/dbs/elki/logging/progress/StepProgress.java6
12 files changed, 115 insertions, 56 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/logging/CLISmartHandler.java b/src/de/lmu/ifi/dbs/elki/logging/CLISmartHandler.java
index f51e6e7e..b4e6cc09 100644
--- a/src/de/lmu/ifi/dbs/elki/logging/CLISmartHandler.java
+++ b/src/de/lmu/ifi/dbs/elki/logging/CLISmartHandler.java
@@ -149,7 +149,7 @@ public class CLISmartHandler extends Handler {
Collection<Progress> completed = ptrack.removeCompleted();
Collection<Progress> progresses = ptrack.getProgresses();
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
if(completed.size() > 0) {
buf.append(OutputStreamLogger.CARRIAGE_RETURN);
for(Progress prog : completed) {
@@ -166,7 +166,7 @@ public class CLISmartHandler extends Handler {
first = false;
}
else {
- buf.append(" ");
+ buf.append(' ');
}
// TODO: use formatter, somehow?
prog.appendToBuffer(buf);
diff --git a/src/de/lmu/ifi/dbs/elki/logging/ELKILogRecord.java b/src/de/lmu/ifi/dbs/elki/logging/ELKILogRecord.java
index 98a25b01..560e1b0f 100644
--- a/src/de/lmu/ifi/dbs/elki/logging/ELKILogRecord.java
+++ b/src/de/lmu/ifi/dbs/elki/logging/ELKILogRecord.java
@@ -52,12 +52,12 @@ public class ELKILogRecord extends LogRecord {
/**
* Classes to ignore when finding the relevant caller.
*/
- public final static String[] IGNORE_CLASSES = { Logger.class.getCanonicalName(), Logging.class.getCanonicalName(), LoggingUtil.class.getCanonicalName(), ELKILogRecord.class.getCanonicalName(), AbstractParameterization.class.getCanonicalName(), AbstractApplication.class.getCanonicalName() };
+ public static final String[] IGNORE_CLASSES = { Logger.class.getCanonicalName(), Logging.class.getCanonicalName(), LoggingUtil.class.getCanonicalName(), ELKILogRecord.class.getCanonicalName(), AbstractParameterization.class.getCanonicalName(), AbstractApplication.class.getCanonicalName() };
/**
* Name of this class.
*/
- private final static String START_TRACE_AT = Logger.class.getCanonicalName();
+ private static final String START_TRACE_AT = Logger.class.getCanonicalName();
/**
* Constructor.
diff --git a/src/de/lmu/ifi/dbs/elki/logging/ErrorFormatter.java b/src/de/lmu/ifi/dbs/elki/logging/ErrorFormatter.java
index cd307275..827108aa 100644
--- a/src/de/lmu/ifi/dbs/elki/logging/ErrorFormatter.java
+++ b/src/de/lmu/ifi/dbs/elki/logging/ErrorFormatter.java
@@ -1,5 +1,28 @@
package de.lmu.ifi.dbs.elki.logging;
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2012
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
@@ -17,7 +40,7 @@ public class ErrorFormatter extends Formatter {
*
* TODO: make configurable via logging.properties
*/
- public static String[] PRUNE = {//
+ public static final String[] PRUNE = {//
"de.lmu.ifi.dbs.elki.gui.minigui.MiniGUI", //
"de.lmu.ifi.dbs.elki.KDDTask", //
"java.awt.event.", //
@@ -40,15 +63,20 @@ public class ErrorFormatter extends Formatter {
@Override
public String format(LogRecord record) {
- if(record instanceof ProgressLogRecord) {
+ if (record instanceof ProgressLogRecord) {
return record.getMessage();
}
String msg = record.getMessage();
- StringBuffer buf = new StringBuffer(msg);
- if(!msg.endsWith(OutputStreamLogger.NEWLINE)) {
- buf.append(OutputStreamLogger.NEWLINE);
+ StringBuilder buf = new StringBuilder();
+ if (msg != null) {
+ buf.append(msg);
+ if (!msg.endsWith(OutputStreamLogger.NEWLINE)) {
+ buf.append(OutputStreamLogger.NEWLINE);
+ }
+ } else {
+ buf.append("null" + OutputStreamLogger.NEWLINE);
}
- if(record.getThrown() != null) {
+ if (record.getThrown() != null) {
appendCauses(buf, record.getThrown());
}
return buf.toString();
@@ -60,31 +88,31 @@ public class ErrorFormatter extends Formatter {
* @param buf Buffer to append to
* @param thrown Throwable to format.
*/
- private void appendCauses(StringBuffer buf, Throwable thrown) {
+ private void appendCauses(StringBuilder buf, Throwable thrown) {
buf.append(thrown.toString()).append(OutputStreamLogger.NEWLINE);
StackTraceElement[] stack = thrown.getStackTrace();
int end = stack.length - 1;
- prune: for(; end >= 0; end--) {
+ prune: for (; end >= 0; end--) {
String cn = stack[end].getClassName();
- for(String pat : PRUNE) {
- if(cn.startsWith(pat)) {
+ for (String pat : PRUNE) {
+ if (cn.startsWith(pat)) {
continue prune;
}
}
break;
}
- if(end <= 0) {
+ if (end <= 0) {
end = stack.length - 1;
}
- for(int i = 0; i <= end; i++) {
+ for (int i = 0; i <= end; i++) {
buf.append("\tat ").append(stack[i]).append(OutputStreamLogger.NEWLINE);
}
- if(end < stack.length - 1) {
+ if (end < stack.length - 1) {
buf.append("\tat [...]").append(OutputStreamLogger.NEWLINE);
}
- if(thrown.getCause() != null) {
+ if (thrown.getCause() != null) {
buf.append("Caused by: ");
appendCauses(buf, thrown.getCause());
}
}
-} \ No newline at end of file
+}
diff --git a/src/de/lmu/ifi/dbs/elki/logging/Logging.java b/src/de/lmu/ifi/dbs/elki/logging/Logging.java
index ea412905..807d4b6e 100644
--- a/src/de/lmu/ifi/dbs/elki/logging/Logging.java
+++ b/src/de/lmu/ifi/dbs/elki/logging/Logging.java
@@ -61,7 +61,7 @@ public class Logging {
private static HashMap<String, Logging> loggers = new HashMap<String, Logging>();
/**
- * Wrapped logger
+ * Wrapped logger of this instance - not static!
*/
private final Logger logger;
@@ -108,9 +108,9 @@ public class Logging {
public boolean isLoggable(Level lev) {
return logger.isLoggable(lev);
}
-
+
/**
- * Test whether to log 'verbose'.
+ * Test whether to log 'verbose' aka 'info'.
*
* @return true if verbose
*/
@@ -119,6 +119,15 @@ public class Logging {
}
/**
+ * Test whether to log 'info' aka 'verbose'.
+ *
+ * @return true if verbose
+ */
+ public boolean isInfo() {
+ return logger.isLoggable(Level.INFO);
+ }
+
+ /**
* Test whether to log 'debug' at 'FINE' level.
*
* This is the same as {@link #isDebuggingFine}
@@ -253,6 +262,29 @@ public class Logging {
}
/**
+ * Log a message at the 'info' ('verbose') level.
+ *
+ * You should check isVerbose() before building the message.
+ *
+ * @param message Informational log message.
+ * @param e Exception
+ */
+ public void info(CharSequence message, Throwable e) {
+ log(Level.INFO, message, e);
+ }
+
+ /**
+ * Log a message at the 'info' ('verbose') level.
+ *
+ * You should check isVerbose() before building the message.
+ *
+ * @param message Informational log message.
+ */
+ public void info(CharSequence message) {
+ log(Level.INFO, message);
+ }
+
+ /**
* Log a message at the 'fine' debugging level.
*
* You should check isDebugging() before building the message.
@@ -429,7 +461,8 @@ public class Logging {
* @param e Exception
*/
public void exception(Throwable e) {
- log(Level.SEVERE, e.getMessage(), e);
+ final String msg = e.getMessage();
+ log(Level.SEVERE, msg != null ? msg : "An exception occurred.", e);
}
/**
diff --git a/src/de/lmu/ifi/dbs/elki/logging/LoggingConfiguration.java b/src/de/lmu/ifi/dbs/elki/logging/LoggingConfiguration.java
index a5f507a7..b0e7936b 100644
--- a/src/de/lmu/ifi/dbs/elki/logging/LoggingConfiguration.java
+++ b/src/de/lmu/ifi/dbs/elki/logging/LoggingConfiguration.java
@@ -112,7 +112,7 @@ public final class LoggingConfiguration {
InputStream cfgdata2 = FileUtil.openSystemFile(cfgfile);
Properties cfgprop = new Properties();
cfgprop.load(cfgdata2);
- DEBUG = Boolean.valueOf(cfgprop.getProperty("debug"));
+ DEBUG = Boolean.parseBoolean(cfgprop.getProperty("debug"));
logger.info("Logging configuration read.");
}
@@ -150,10 +150,10 @@ public final class LoggingConfiguration {
}
else {
// increase to warning level if it was INFO.
- if(logger1.getLevel() != null || logger1.getLevel() == Level.INFO) {
+ if(logger1.getLevel() == null || Level.INFO.equals(logger1.getLevel())) {
logger1.setLevel(Level.WARNING);
}
- if(logger2.getLevel() != null || logger2.getLevel() == Level.INFO) {
+ if(logger2.getLevel() == null || Level.INFO.equals(logger2.getLevel())) {
logger2.setLevel(Level.WARNING);
}
}
diff --git a/src/de/lmu/ifi/dbs/elki/logging/LoggingUtil.java b/src/de/lmu/ifi/dbs/elki/logging/LoggingUtil.java
index 808a648c..1a48fc7a 100644
--- a/src/de/lmu/ifi/dbs/elki/logging/LoggingUtil.java
+++ b/src/de/lmu/ifi/dbs/elki/logging/LoggingUtil.java
@@ -53,7 +53,7 @@ public final class LoggingUtil {
* @param message Message to log.
* @param e Exception to report.
*/
- public final static void logExpensive(Level level, String message, Throwable e) {
+ public static final void logExpensive(Level level, String message, Throwable e) {
String[] caller = inferCaller();
if(caller != null) {
Logger logger = Logger.getLogger(caller[0]);
@@ -74,7 +74,7 @@ public final class LoggingUtil {
* @param level Logging level
* @param message Message to log.
*/
- public final static void logExpensive(Level level, String message) {
+ public static final void logExpensive(Level level, String message) {
LogRecord rec = new ELKILogRecord(level, message);
String[] caller = inferCaller();
if(caller != null) {
@@ -93,7 +93,7 @@ public final class LoggingUtil {
*
* @param e Exception to log
*/
- public final static void exception(Throwable e) {
+ public static final void exception(Throwable e) {
logExpensive(Level.SEVERE, e.getMessage(), e);
}
@@ -103,7 +103,7 @@ public final class LoggingUtil {
* @param message Exception message, may be null (defaults to e.getMessage())
* @param e causing exception
*/
- public final static void exception(String message, Throwable e) {
+ public static final void exception(String message, Throwable e) {
if(message == null && e != null) {
message = e.getMessage();
}
@@ -115,7 +115,7 @@ public final class LoggingUtil {
*
* @param message Warning message.
*/
- public final static void warning(String message) {
+ public static final void warning(String message) {
logExpensive(Level.WARNING, message);
}
@@ -125,7 +125,7 @@ public final class LoggingUtil {
* @param message Warning message, may be null (defaults to e.getMessage())
* @param e causing exception
*/
- public final static void warning(String message, Throwable e) {
+ public static final void warning(String message, Throwable e) {
if(message == null && e != null) {
message = e.getMessage();
}
@@ -137,7 +137,7 @@ public final class LoggingUtil {
*
* @param message Warning message.
*/
- public final static void message(String message) {
+ public static final void message(String message) {
logExpensive(Level.INFO, message);
}
@@ -147,7 +147,7 @@ public final class LoggingUtil {
* @param message Warning message, may be null (defaults to e.getMessage())
* @param e causing exception
*/
- public final static void message(String message, Throwable e) {
+ public static final void message(String message, Throwable e) {
if(message == null && e != null) {
message = e.getMessage();
}
@@ -163,7 +163,7 @@ public final class LoggingUtil {
*
* @return calling class name and calling method name
*/
- private final static String[] inferCaller() {
+ private static final String[] inferCaller() {
StackTraceElement stack[] = (new Throwable()).getStackTrace();
int ix = 0;
while(ix < stack.length) {
diff --git a/src/de/lmu/ifi/dbs/elki/logging/progress/AbstractProgress.java b/src/de/lmu/ifi/dbs/elki/logging/progress/AbstractProgress.java
index 070dbdb9..1d196533 100644
--- a/src/de/lmu/ifi/dbs/elki/logging/progress/AbstractProgress.java
+++ b/src/de/lmu/ifi/dbs/elki/logging/progress/AbstractProgress.java
@@ -109,7 +109,7 @@ public abstract class AbstractProgress implements Progress {
* @return Buffer the data was serialized to.
*/
@Override
- public abstract StringBuffer appendToBuffer(StringBuffer buf);
+ public abstract StringBuilder appendToBuffer(StringBuilder buf);
/**
* Returns a String representation of the progress suitable as a message for
@@ -119,7 +119,7 @@ public abstract class AbstractProgress implements Progress {
*/
@Override
public String toString() {
- StringBuffer message = new StringBuffer();
+ StringBuilder message = new StringBuilder();
appendToBuffer(message);
return message.toString();
}
diff --git a/src/de/lmu/ifi/dbs/elki/logging/progress/FiniteProgress.java b/src/de/lmu/ifi/dbs/elki/logging/progress/FiniteProgress.java
index 6d70b560..1ddc02f7 100644
--- a/src/de/lmu/ifi/dbs/elki/logging/progress/FiniteProgress.java
+++ b/src/de/lmu/ifi/dbs/elki/logging/progress/FiniteProgress.java
@@ -82,10 +82,10 @@ public class FiniteProgress extends AbstractProgress {
*/
@Override
public void setProcessed(int processed) throws IllegalArgumentException {
- if(processed > total) {
+ if (processed > total) {
throw new IllegalArgumentException(processed + " exceeds total: " + total);
}
- if(processed < 0) {
+ if (processed < 0) {
throw new IllegalArgumentException("Negative number of processed: " + processed);
}
super.setProcessed(processed);
@@ -98,20 +98,20 @@ public class FiniteProgress extends AbstractProgress {
* @return Buffer the data was serialized to.
*/
@Override
- public StringBuffer appendToBuffer(StringBuffer buf) {
+ public StringBuilder appendToBuffer(StringBuilder buf) {
String processedString = Integer.toString(getProcessed());
int percentage = (int) (getProcessed() * 100.0 / total);
buf.append(getTask());
buf.append(": ");
- for(int i = 0; i < totalLength - processedString.length(); i++) {
+ for (int i = 0; i < totalLength - processedString.length(); i++) {
buf.append(' ');
}
buf.append(getProcessed());
buf.append(" [");
- if(percentage < 100) {
+ if (percentage < 100) {
buf.append(' ');
}
- if(percentage < 10) {
+ if (percentage < 10) {
buf.append(' ');
}
buf.append(percentage);
@@ -142,10 +142,10 @@ public class FiniteProgress extends AbstractProgress {
* @param logger Logger to report to.
*/
public void ensureCompleted(Logging logger) {
- if(!isComplete()) {
- logger.warning("Progress had not completed automatically as expected.", new Throwable());
+ if (!isComplete()) {
+ logger.warning("Progress had not completed automatically as expected: " + getProcessed() + "/" + total, new Throwable());
setProcessed(getTotal());
logger.progress(this);
}
}
-} \ No newline at end of file
+}
diff --git a/src/de/lmu/ifi/dbs/elki/logging/progress/IndefiniteProgress.java b/src/de/lmu/ifi/dbs/elki/logging/progress/IndefiniteProgress.java
index 9a13947c..1dd61674 100644
--- a/src/de/lmu/ifi/dbs/elki/logging/progress/IndefiniteProgress.java
+++ b/src/de/lmu/ifi/dbs/elki/logging/progress/IndefiniteProgress.java
@@ -61,7 +61,7 @@ public class IndefiniteProgress extends AbstractProgress {
* Serialize 'indefinite' progress.
*/
@Override
- public StringBuffer appendToBuffer(StringBuffer buf) {
+ public StringBuilder appendToBuffer(StringBuilder buf) {
buf.append(getTask());
buf.append(": ");
buf.append(getProcessed());
diff --git a/src/de/lmu/ifi/dbs/elki/logging/progress/Progress.java b/src/de/lmu/ifi/dbs/elki/logging/progress/Progress.java
index 972f0c58..74125798 100644
--- a/src/de/lmu/ifi/dbs/elki/logging/progress/Progress.java
+++ b/src/de/lmu/ifi/dbs/elki/logging/progress/Progress.java
@@ -23,7 +23,6 @@ package de.lmu.ifi.dbs.elki.logging.progress;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
/**
* Generic Progress logging interface.
*
@@ -36,14 +35,14 @@ public interface Progress {
* @param buf Buffer to serialize to
* @return Buffer the data was serialized to.
*/
- public StringBuffer appendToBuffer(StringBuffer buf);
+ StringBuilder appendToBuffer(StringBuilder buf);
/**
* Test whether a progress is complete (and thus doesn't need to be shown anymore)
*
* @return Whether the progress was completed.
*/
- public boolean isComplete();
+ boolean isComplete();
/**
* Returns a String representation of the progress suitable as a message for
@@ -52,5 +51,5 @@ public interface Progress {
* @see java.lang.Object#toString()
*/
@Override
- public String toString();
+ String toString();
} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/logging/progress/ProgressTracker.java b/src/de/lmu/ifi/dbs/elki/logging/progress/ProgressTracker.java
index d39e3107..ad3f7c37 100644
--- a/src/de/lmu/ifi/dbs/elki/logging/progress/ProgressTracker.java
+++ b/src/de/lmu/ifi/dbs/elki/logging/progress/ProgressTracker.java
@@ -28,7 +28,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import java.util.Vector;
/**
* Class to keep track of "alive" progresses.
@@ -41,7 +40,7 @@ public class ProgressTracker {
/**
* Set of potentially active progresses.
*/
- private Vector<WeakReference<Progress>> progresses = new Vector<WeakReference<Progress>>();
+ private ArrayList<WeakReference<Progress>> progresses = new ArrayList<WeakReference<Progress>>();
/**
* Get a list of progresses tracked.
diff --git a/src/de/lmu/ifi/dbs/elki/logging/progress/StepProgress.java b/src/de/lmu/ifi/dbs/elki/logging/progress/StepProgress.java
index df6e3b13..1a0d3101 100644
--- a/src/de/lmu/ifi/dbs/elki/logging/progress/StepProgress.java
+++ b/src/de/lmu/ifi/dbs/elki/logging/progress/StepProgress.java
@@ -62,15 +62,15 @@ public class StepProgress extends FiniteProgress {
// No constructor with auto logging - call beginStep() first
@Override
- public StringBuffer appendToBuffer(StringBuffer buf) {
+ public StringBuilder appendToBuffer(StringBuilder buf) {
buf.append(super.getTask());
if (isComplete()) {
buf.append(": complete.");
} else {
- buf.append(" #").append(getProcessed()+1).append("/").append(getTotal());
+ buf.append(" #").append(getProcessed()+1).append('/').append(getTotal());
buf.append(": ").append(getStepTitle());
}
- buf.append("\n");
+ buf.append('\n');
return buf;
}