X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FTraceHandler.java;fp=src%2Fbe%2Fnikiroo%2Futils%2FTraceHandler.java;h=5fa08438c3abe2e1a01e916d37f8d83b9c84ae8f;hp=0000000000000000000000000000000000000000;hb=530d4062471346d6ececf76d74a0358c91323998;hpb=2ee6c205bfacff9e9a3103e7738afcd5e3267d3f diff --git a/src/be/nikiroo/utils/TraceHandler.java b/src/be/nikiroo/utils/TraceHandler.java new file mode 100644 index 0000000..5fa0843 --- /dev/null +++ b/src/be/nikiroo/utils/TraceHandler.java @@ -0,0 +1,88 @@ +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 boolean showErrorDetails; + private boolean showTraces; + + /** + * Show more details (usually equivalent to the value of DEBUG). + * + * @return TRUE or FALSE + */ + public boolean isShowErrorDetails() { + return showErrorDetails; + } + + /** + * Show more details (usually equivalent to the value of DEBUG). + * + * @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. + * + * @param showTraces + * TRUE or FALSE + */ + public void setShowTraces(boolean showTraces) { + this.showTraces = showTraces; + } + + /** + * An exception happened, log it. + * + * @param e + * the exception + */ + public void error(Exception e) { + if (isShowErrorDetails()) { + e.printStackTrace(); + } else { + error(e.getMessage()); + } + } + + /** + * An error happened, log it. + * + * @param message + * the error message + */ + public void error(String message) { + System.err.println(message); + } + + /** + * A trace happened, show it. + *

+ * Will only be effective if {@link TraceHandler#isShowTraces()} is true. + * + * @param message + * the trace message + */ + public void trace(String message) { + if (isShowTraces()) { + System.out.println(message); + } + } +}