Class Debug

java.lang.Object
de.spiritscorp.datasync.io.Debug

public final class Debug extends Object
Utility class providing centralized logging capabilities for application diagnostics, errors, and exception tracking. All outputs are automatically enriched with a timestamp and the active application instance name.
Version:
1.2.0
Author:
Tom Spirit
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    initDebugToFile(Path debugPath, Path errorPath)
    Initializes the logging subsystem by executing log rotation on the provided paths.
    static void
    printDebug(String format, Object... args)
    Writes a formatted debugging message to the standard output stream (stdout).
    static void
    printDebugTimeless(String format, Object... args)
    A debug method to write a formatted string to this output stream using the specified format string and arguments.
    static void
    printError(String format, Object... args)
    Writes a formatted error message to the standard error stream (stderr).
    static void
    printException(Class<?> clazz, Exception exception)
    Logs or prints detailed diagnostic information about a caught exception.
    static void
    Redirects standard output (System.out) and standard error (System.err) streams to their respective designated local log files.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • initDebugToFile

      public static void initDebugToFile(Path debugPath, Path errorPath)
      Initializes the logging subsystem by executing log rotation on the provided paths.

      This method ensures idempotent execution; if the framework is already initialized, subsequent calls will return immediately without repeating the rotation.

      Parameters:
      debugPath - the path to the diagnostic debug log file
      errorPath - the path to the error log file
    • printDebug

      public static void printDebug(String format, Object... args)
      Writes a formatted debugging message to the standard output stream (stdout). The output is automatically prefixed with a current timestamp and the running instance name.
      Parameters:
      format - A format string as described in Formatter syntax
      args - Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by The Java Virtual Machine Specification.
    • printError

      public static void printError(String format, Object... args)
      Writes a formatted error message to the standard error stream (stderr). The output is automatically prefixed with a current timestamp and the running instance name.
      Parameters:
      format - A format string as described in Formatter syntax
      args - Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by The Java Virtual Machine Specification.
    • printException

      public static void printException(Class<?> clazz, Exception exception)
      Logs or prints detailed diagnostic information about a caught exception.

      This utility method formats and outputs the primary exception message, inspects and logs the root cause if present to prevent NullPointerException, and extracts the complete formatted stack trace for deep debugging.

      * Example Output Structure:

      Exception in Class: [com.example.MyService]:Message -> Connection failed
      ↳ Cause: java.net.ConnectException -> Message: Connection refused
      Full Info:
      java.lang.RuntimeException: Connection failed
      at com.example.MyService.start(MyService.java:24)
      ...
      

      Parameters:
      clazz - the Class context where the exception was caught, used for identification
      exception - the Exception instance containing the error details and stack trace
    • printDebugTimeless

      public static void printDebugTimeless(String format, Object... args)
      A debug method to write a formatted string to this output stream using the specified format string and arguments.
      Parameters:
      format - A format string as described in Formatter syntax
      args - Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by The Java Virtual Machine Specification.
    • setDebugToFile

      public static void setDebugToFile()
      Redirects standard output (System.out) and standard error (System.err) streams to their respective designated local log files.

      If the logging system has not been initialized yet, this method automatically triggers the log rotation sequence first. Once both file streams are successfully established, any diagnostic messages captured in the memory buffers during the rotation phase are immediately flushed to their corresponding destination files.