/** * Gets the current writer that will used for debugging output. If no writer was explicitely set by the user, the * default writer is returned. * * @return the current writer, or <code>null</code> if debugging is disabled */ public static PrintWriter getWriter() { if (isEnabled() && _writer == null) { _writer = getDefaultWriter(); } return _writer; }
/** * Gets the default writer used for debugging output. * * @return the default writer, or <code>null</code> if debugging is disabled */ public static PrintWriter getDefaultWriter() { if (isEnabled() && _defaultWriter == null) { _defaultWriter = createPrintWriter(System.out); } return _defaultWriter; }
/** * Sets the current writer that will be used for debugging output. * * @param writer the new writer */ public static void setWriter(Writer writer) { if (isEnabled() && writer != null) { _writer = createPrintWriter(writer); } }
@Override protected void setUp() { _oldDebugState = Debug.isEnabled(); }
/** * Sets the current writer for the given stream that will be used for debugging output. * * @param stream the stream that will be used for debugging output */ public static void setWriter(OutputStream stream) { if (isEnabled() && stream != null) { _writer = createPrintWriter(stream); } }
/** * Prints the given property change event to the current writer if and only if the debugging class functionality is * enabled. */ public static void trace(PropertyChangeEvent event) { if (isEnabled() && event != null) { PrintWriter w = getWriter(); w.print("property "); w.print(event.getPropertyName()); w.print(" changed from "); w.print(event.getOldValue()); w.print(" to "); w.print(event.getNewValue()); w.println(); } }
/** * If the given object is null, and the debugging functionality is enabled, this method throws an * <code>AssertionFailure</code> in order to signal that an internal program post- or pre-condition failed. * <p/> * <p> Use this method whenever a valid state must be ensured within your sourcecode in order to safely continue the * program. * <p/> * <p> For example, the method can be used to ensure valid arguments passed to private and protected methods. * * @param object the object to test for non-null condition * * @throws AssertionFailure if <code>object</code> is null and the debugging functionality is enabled */ public static void assertNotNull(Object object) throws AssertionFailure { if (isEnabled()) { if (object == null) { handleAssertionFailed(UtilConstants.MSG_OBJECT_NULL); } } }
/** * If the <code>condition</code> is NOT true, and the debugging functionality is enabled, this method throws an * <code>AssertionFailure</code> in order to signal that an internal program post- or pre-condition failed. * <p/> * <p> Use this method whenever a valid state must be ensured within your sourcecode in order to safely continue the * program. * <p/> * <p> For example, the method can be used to ensure valid arguments passed to private and protected methods. * * @param condition the assert condition * * @throws AssertionFailure if <code>condition</code> evaluates to false and the debugging functionality is enabled */ public static void assertTrue(boolean condition) throws AssertionFailure { if (isEnabled()) { if (!condition) { handleAssertionFailed(null); } } }
/** * Prints the given message string to the current writer if and only if the debugging class functionality is * enabled. */ public static void trace(String message) { if (isEnabled() && message != null) { PrintWriter w = getWriter(); w.print(_tracePrefix); w.println(message); log(message); } }
/** * If the given String is null or empty, and the debugging functionality is enabled, this method throws an * <code>AssertionFailure</code> in order to signal that an internal program post- or pre-condition failed. * <p/> * <p> Use this method whenever a valid state must be ensured within your sourcecode in order to safely continue the * program. * <p/> * <p> For example, the method can be used to ensure valid arguments passed to private and protected methods. * * @param string the String to test for non-null and not empty condition * * @throws AssertionFailure if <code>String</code> is null or empty and the debugging functionality is enabled */ public static void assertNotNullOrEmpty(String string) throws AssertionFailure { if (isEnabled()) { if (string == null || string.length() < 1) { handleAssertionFailed(UtilConstants.MSG_STRING_NULL_OR_EMPTY); } } }
/** * Delegates <code>Debug.trace()</code> calls to the system logger. * * @param exception the exception to be logged. */ protected static void log(Throwable exception) { if (isEnabled()) { if (isLogging()) { final StringWriter stringWriter = new StringWriter(); final PrintWriter printWriter = new PrintWriter(stringWriter); exception.printStackTrace(printWriter); log(stringWriter.getBuffer().toString()); } } }
/** * If the <code>condition</code> is NOT true, and the debugging functionality is enabled, this method throws an * <code>AssertionFailure</code> in order to signal that an internal program post- or pre-condition failed. The * <code>AssertionFailure</code> will be created with the given error message string. * <p/> * <p> Use this method whenever a valid state must be ensured within your sourcecode in order to safely continue the * program. * <p/> * <p> For example, the method can be used to ensure valid arguments passed to private and protected methods. * * @param condition the assert condition * @param message an error message * * @throws AssertionFailure if <code>condition</code> evaluates to false and the debugging functionality is enabled */ public static void assertTrue(boolean condition, String message) throws AssertionFailure { if (isEnabled()) { if (!condition) { handleAssertionFailed(message); } } }
/** * Prints a 'method not implemented' message using the given class and method name string to the current writer if * and only if the debugging class functionality is enabled. * * @param clazz the method's class * @param methodName the method's name */ public static void traceMethodNotImplemented(Class clazz, String methodName) { if (isEnabled()) { PrintWriter w = getWriter(); w.print(_tracePrefix); w.print(UtilConstants.MSG_METHOD_NOT_IMPLEMENTED); if (methodName != null) { if (clazz != null) { w.print(clazz.getName()); } else { w.print("<unknown class>"); } w.print("."); w.print(methodName); w.print("()"); w.println(); } } }
public void trace(String label) { if (Debug.isEnabled()) { Debug.trace(label + ": " + getTimeDiffString()); } } }
/** * Delegates <code>Debug.trace()</code> calls to the system logger. * * @param message the message to be logged. */ protected static void log(String message) { if (isEnabled()) { if (isLogging()) { if (_logger == null) { _logger = BeamLogManager.getSystemLogger(); } _logger.finest(message); } } }
/** * Prints the stack trace for the given exeption to the current writer if and only if the debugging class * functionality is enabled. */ public static void trace(Throwable exception) { if (isEnabled() && exception != null) { PrintWriter w = getWriter(); w.print(_tracePrefix); w.println(UtilConstants.MSG_EXCEPTION_OCCURRED); exception.printStackTrace(w); log(UtilConstants.MSG_EXCEPTION_OCCURRED); log(exception); } }
/** * Prints the ammount of free memory using the given label string to the current writer if and only if the debugging * class functionality is enabled. * * @param label an optional label, can be null */ public static void traceMemoryUsage(String label) { if (isEnabled()) { String message = createMemoryUsageMessage(label); PrintWriter w = getWriter(); w.print(_tracePrefix); w.println(message); log(message); } }
if (isEnabled()) {
command.add("--log_file"); command.add(BEAMPYUTIL_LOG_FILENAME); if (Debug.isEnabled()) { command.add("--log_level"); command.add("DEBUG");