Class Debug
java.lang.Object
de.spiritscorp.datasync.io.Debug
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 TypeMethodDescriptionstatic voidinitDebugToFile(Path debugPath, Path errorPath) Initializes the logging subsystem by executing log rotation on the provided paths.static voidprintDebug(String format, Object... args) Writes a formatted debugging message to the standard output stream (stdout).static voidprintDebugTimeless(String format, Object... args) A debug method to write a formatted string to this output stream using the specified format string and arguments.static voidprintError(String format, Object... args) Writes a formatted error message to the standard error stream (stderr).static voidprintException(Class<?> clazz, Exception exception) Logs or prints detailed diagnostic information about a caught exception.static voidRedirects standard output (System.out) and standard error (System.err) streams to their respective designated local log files.
-
Method Details
-
initDebugToFile
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 fileerrorPath- the path to the error log file
-
printDebug
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 inFormattersyntaxargs- 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
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 inFormattersyntaxargs- 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
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) ...
-
printDebugTimeless
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 inFormattersyntaxargs- 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.
-