* @author niki
*/
public class TraceHandler {
- private boolean showErrorDetails;
+ private boolean showErrors;
private boolean showTraces;
+ private boolean showErrorDetails;
/**
- * Show more details (usually equivalent to the value of DEBUG).
- *
- * @return TRUE or FALSE
+ * Create a default {@link TraceHandler} that will print errors on stderr
+ * (without details) and no traces.
*/
- public boolean isShowErrorDetails() {
- return showErrorDetails;
+ public TraceHandler() {
+ this(true, false, false);
}
/**
- * Show more details (usually equivalent to the value of DEBUG).
+ * Create a default {@link TraceHandler}.
*
+ * @param showErrors
+ * show errors on stderr
* @param showErrorDetails
- * TRUE or FALSE
- */
- public void setShowErrorDetails(boolean showErrorDetails) {
- this.showErrorDetails = showErrorDetails;
- }
-
- /**
- * Show DEBUG traces.
- *
- * @return TRUE or FALSE
- */
- public boolean isShowTraces() {
- return showTraces;
- }
-
- /**
- * Show DEBUG traces.
- *
+ * show more details when printing errors
* @param showTraces
- * TRUE or FALSE
+ * show traces on stdout
*/
- public void setShowTraces(boolean showTraces) {
+ public TraceHandler(boolean showErrors, boolean showErrorDetails,
+ boolean showTraces) {
+ this.showErrors = showErrors;
+ this.showErrorDetails = showErrorDetails;
this.showTraces = showTraces;
}
* the exception
*/
public void error(Exception e) {
- if (isShowErrorDetails()) {
- e.printStackTrace();
- } else {
- error(e.getMessage());
+ if (showErrors) {
+ if (showErrorDetails) {
+ e.printStackTrace();
+ } else {
+ error(e.getMessage());
+ }
}
}
* the error message
*/
public void error(String message) {
- System.err.println(message);
+ if (showErrors) {
+ System.err.println(message);
+ }
}
/**
* A trace happened, show it.
* <p>
- * Will only be effective if {@link TraceHandler#isShowTraces()} is true.
+ * Will only be effective if {@link TraceHandler#showTraces} is true.
*
* @param message
* the trace message
*/
public void trace(String message) {
- if (isShowTraces()) {
+ if (showTraces) {
System.out.println(message);
}
}
+
+ // old stuff:
+
+ /**
+ * Use the parameters in the constructor instead.
+ *
+ * @param showTraces
+ * show the traces
+ */
+ @Deprecated
+ public void setShowTraces(boolean showTraces) {
+ this.showTraces = showTraces;
+ }
+
+ /**
+ * Use the parameters in the constructor instead.
+ *
+ * @param showErrorDetails
+ * show the details on errors
+ */
+ @Deprecated
+ public void setShowErrorDetails(boolean showErrorDetails) {
+ this.showErrorDetails = showErrorDetails;
+ }
}