Package org.pjdbc.debug
Class DebugEventListener
java.lang.Object
org.pjdbc.debug.DebugEventListener
- All Implemented Interfaces:
PjdbcEventListener
Pre-built event listener that logs all PJDBC events for debugging.
Usage:
// Enable debug logging
PjdbcDebug.enable();
// Or with custom output
PjdbcDebug.enable(System.err);
// Or register directly
PjdbcListeners.register(new DebugEventListener());
Output format:
[PJDBC 14:23:45.123] RETRY sql="SELECT..." attempt=2 delay=100ms cause="Connection reset" [PJDBC 14:23:45.234] CIRCUIT_BREAKER name="default" CLOSED → OPEN [PJDBC 14:23:45.345] SQL_TRANSFORM "SELECT *" → "SELECT id, name"
- Since:
- 2.3.0
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a debug listener that writes to System.err.Create a debug listener with custom output.DebugEventListener(PrintStream out, boolean includeStackTrace) Create a debug listener with custom output and stack trace option. -
Method Summary
Modifier and TypeMethodDescriptionvoidonChaosInjected(String type, String sql, String details) Called when chaos injection occurs (for ChaosDriver).voidonCircuitBreakerRejection(String name, String state) Called when a request is rejected by a circuit breaker.voidonCircuitBreakerStateChange(String name, String oldState, String newState) Called when a circuit breaker changes state.voidonFederatedQuery(String sql, List<String> targetUrls) Called when a query is executed against multiple federated databases.voidonRetry(String sql, SQLException cause, int attempt, long delayMs) Called when a retry is about to be attempted.voidonSqlTransformed(String original, String transformed) Called when SQL is transformed by a filter driver.
-
Constructor Details
-
DebugEventListener
public DebugEventListener()Create a debug listener that writes to System.err. -
DebugEventListener
Create a debug listener with custom output.- Parameters:
out- the output stream
-
DebugEventListener
Create a debug listener with custom output and stack trace option.- Parameters:
out- the output streamincludeStackTrace- whether to include stack traces for errors
-
-
Method Details
-
onRetry
Description copied from interface:PjdbcEventListenerCalled when a retry is about to be attempted.- Specified by:
onRetryin interfacePjdbcEventListener- Parameters:
sql- the SQL statement being retried (may be null for non-SQL operations)cause- the exception that triggered the retryattempt- the retry attempt number (1 for first retry, 2 for second, etc.)delayMs- the delay in milliseconds before the retry will be attempted
-
onCircuitBreakerStateChange
Description copied from interface:PjdbcEventListenerCalled when a circuit breaker changes state.- Specified by:
onCircuitBreakerStateChangein interfacePjdbcEventListener- Parameters:
name- the circuit breaker nameoldState- the previous state (CLOSED, OPEN, or HALF_OPEN)newState- the new state
-
onSqlTransformed
Description copied from interface:PjdbcEventListenerCalled when SQL is transformed by a filter driver.- Specified by:
onSqlTransformedin interfacePjdbcEventListener- Parameters:
original- the original SQL statementtransformed- the transformed SQL statement
-
onFederatedQuery
Description copied from interface:PjdbcEventListenerCalled when a query is executed against multiple federated databases.- Specified by:
onFederatedQueryin interfacePjdbcEventListener- Parameters:
sql- the SQL statement being executedtargetUrls- the JDBC URLs of the target databases
-
onCircuitBreakerRejection
Description copied from interface:PjdbcEventListenerCalled when a request is rejected by a circuit breaker.- Specified by:
onCircuitBreakerRejectionin interfacePjdbcEventListener- Parameters:
name- the circuit breaker namestate- the current circuit breaker state
-
onChaosInjected
Description copied from interface:PjdbcEventListenerCalled when chaos injection occurs (for ChaosDriver).- Specified by:
onChaosInjectedin interfacePjdbcEventListener- Parameters:
type- the type of chaos injected (e.g., "delay", "exception", "timeout")sql- the SQL statement affected (may be null)details- additional details about the chaos injection
-