Package org.jdbi.v3.core.statement
Interface SqlLogger
-
- All Known Implementing Classes:
Slf4JSqlLogger
public interface SqlLoggerSqlLoggers receive query data before and after a query is executed, and after an exception is thrown by a bad query. Defined attributes (seeConfigurable.define(String, Object)) and boundArguments (seeSqlStatement.bind(String, Object)) are available on theStatementContext, along with timing information usingInstants. It's recommendable to useChronoUnit.between(java.time.temporal.Temporal, java.time.temporal.Temporal)to measure elapsed time in your unit of choice, as inStatementContext.getElapsedTime(java.time.temporal.ChronoUnit). Note that if youbindanArgumentinstance directly, it must implementObject.toString()if you want to be able to log it in any meaningful way. You can also implement log censorship that way, e.g. to hide sensitive content like passwords.
-
-
Field Summary
Fields Modifier and Type Field Description static SqlLoggerNOP_SQL_LOGGER
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default voidlogAfterExecution(StatementContext context)Will be called after a query has been executed.default voidlogBeforeExecution(StatementContext context)Will be called before a query is executed.default voidlogException(StatementContext context, java.sql.SQLException ex)Will be called after a query has failed.
-
-
-
Field Detail
-
NOP_SQL_LOGGER
static final SqlLogger NOP_SQL_LOGGER
-
-
Method Detail
-
logBeforeExecution
default void logBeforeExecution(StatementContext context)
Will be called before a query is executed. Note that no timing information will be available in theStatementContextyet.- Parameters:
context- the statement context
-
logAfterExecution
default void logAfterExecution(StatementContext context)
Will be called after a query has been executed. TheStatementContextwill contain a startStatementContext.getExecutionMoment()and endStatementContext.getCompletionMoment()time.- Parameters:
context- the statement context
-
logException
default void logException(StatementContext context, java.sql.SQLException ex)
Will be called after a query has failed. TheStatementContextwill contain a startStatementContext.getExecutionMoment()and failureStatementContext.getExceptionMoment()time.- Parameters:
context- the statement contextex- the exception
-
-