Interface SqlLogger
- All Known Implementing Classes:
Slf4JSqlLogger
public interface SqlLogger
SqlLoggers receive query data before and after a query is executed, and after an exception is thrown by a bad query.
Defined attributes (see
Configurable.define(String, Object)
) and bound Argument
s (see SqlStatement.bind(String, Object)
) are available on the StatementContext
, along with timing information using Instant
s. It's recommendable to use ChronoUnit.between(java.time.temporal.Temporal, java.time.temporal.Temporal)
to measure elapsed time in your unit of choice, as in StatementContext.getElapsedTime(java.time.temporal.ChronoUnit)
.
Note that if you bind
an Argument
instance directly, it must implement Object.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
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
logAfterExecution
(StatementContext context) Will be called after a query has been executed.default void
logBeforeExecution
(StatementContext context) Will be called before a query is executed.default void
logException
(StatementContext context, SQLException ex) Will be called after a query has failed.
-
Field Details
-
NOP_SQL_LOGGER
-
-
Method Details
-
logBeforeExecution
Will be called before a query is executed. Note that no timing information will be available in theStatementContext
yet.- Parameters:
context
- the statement context
-
logAfterExecution
Will be called after a query has been executed. TheStatementContext
will contain a startStatementContext.getExecutionMoment()
and endStatementContext.getCompletionMoment()
time.- Parameters:
context
- the statement context
-
logException
Will be called after a query has failed. TheStatementContext
will contain a startStatementContext.getExecutionMoment()
and failureStatementContext.getExceptionMoment()
time.- Parameters:
context
- the statement contextex
- the exception
-