X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FTraceHandler.java;h=0a09712d5218013992493838c75ad9aa0ad92527;hb=9e7330d793887fe9ee378ca1413141d7761e76ca;hp=12ae849b0d267e56d2971937b87b5c0765de73c6;hpb=e361afe469e252cb4f04f64ec8baf5c27d4b9917;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/TraceHandler.java b/src/be/nikiroo/utils/TraceHandler.java deleted file mode 100644 index 12ae849..0000000 --- a/src/be/nikiroo/utils/TraceHandler.java +++ /dev/null @@ -1,150 +0,0 @@ -package be.nikiroo.utils; - -/** - * A handler when a trace message is sent or when a recoverable exception was - * caught by the program. - * - * @author niki - */ -public class TraceHandler { - private final boolean showErrors; - private final boolean showErrorDetails; - private final int traceLevel; - private final int maxPrintSize; - - /** - * Create a default {@link TraceHandler} that will print errors on stderr - * (without details) and no traces. - */ - public TraceHandler() { - this(true, false, false); - } - - /** - * Create a default {@link TraceHandler}. - * - * @param showErrors - * show errors on stderr - * @param showErrorDetails - * show more details when printing errors - * @param showTraces - * show level 1 traces on stderr, or no traces at all - */ - public TraceHandler(boolean showErrors, boolean showErrorDetails, - boolean showTraces) { - this(showErrors, showErrorDetails, showTraces ? 1 : 0); - } - - /** - * Create a default {@link TraceHandler}. - * - * @param showErrors - * show errors on stderr - * @param showErrorDetails - * show more details when printing errors - * @param traceLevel - * show traces of this level or lower (0 means "no traces", - * higher means more traces) - */ - public TraceHandler(boolean showErrors, boolean showErrorDetails, - int traceLevel) { - this(showErrors, showErrorDetails, traceLevel, -1); - } - - /** - * Create a default {@link TraceHandler}. - * - * @param showErrors - * show errors on stderr - * @param showErrorDetails - * show more details when printing errors - * @param traceLevel - * show traces of this level or lower (0 means "no traces", - * higher means more traces) - * @param maxPrintSize - * the maximum size at which to truncate traces data (or -1 for - * "no limit") - */ - public TraceHandler(boolean showErrors, boolean showErrorDetails, - int traceLevel, int maxPrintSize) { - this.showErrors = showErrors; - this.showErrorDetails = showErrorDetails; - this.traceLevel = Math.max(traceLevel, 0); - this.maxPrintSize = maxPrintSize; - } - - /** - * The trace level of this {@link TraceHandler}. - * - * @return the level - */ - public int getTraceLevel() { - return traceLevel; - } - - /** - * An exception happened, log it. - * - * @param e - * the exception - */ - public void error(Exception e) { - if (showErrors) { - if (showErrorDetails) { - e.printStackTrace(); - } else { - error(e.getMessage()); - } - } - } - - /** - * An error happened, log it. - * - * @param message - * the error message - */ - public void error(String message) { - if (showErrors) { - System.err.println(message); - } - } - - /** - * A trace happened, show it. - *

- * By default, will only be effective if {@link TraceHandler#traceLevel} is - * not 0. - *

- * A call to this method is equivalent to a call to - * {@link TraceHandler#trace(String, int)} with a level of 1. - * - * @param message - * the trace message - */ - public void trace(String message) { - trace(message, 1); - } - - /** - * A trace happened, show it. - *

- * By default, will only be effective if {@link TraceHandler#traceLevel} is - * not 0 and the level is lower or equal to it. - * - * @param message - * the trace message - * @param level - * the trace level - */ - public void trace(String message, int level) { - if (traceLevel > 0 && level <= traceLevel) { - if (maxPrintSize > 0 && message.length() > maxPrintSize) { - System.err - .println(message.substring(0, maxPrintSize) + "[...]"); - } else { - System.err.println(message); - } - } - } -}