Class SqlStatementLogger

java.lang.Object
org.hibernate.engine.jdbc.spi.SqlStatementLogger
All Implemented Interfaces:
Serializable, Service

public class SqlStatementLogger extends Object implements Service

Centralize logging for SQL statements, with some configuration:

Some of these configuration values can be adjusted at runtime.

See Also:
  • Constructor Details

    • SqlStatementLogger

      public SqlStatementLogger()
      Constructs a new SqlStatementLogger instance.
    • SqlStatementLogger

      public SqlStatementLogger(boolean logToStdout, boolean format)
      Constructs a new SqlStatementLogger instance.
      Parameters:
      logToStdout - Should we log to STDOUT in addition to our internal logger?
      format - Should we format the statements in the console and log
    • SqlStatementLogger

      public SqlStatementLogger(boolean logToStdout, boolean format, boolean highlight)
      Constructs a new SqlStatementLogger instance.
      Parameters:
      logToStdout - Should we log to STDOUT in addition to our internal logger?
      format - Should we format the statements in the console and log
      highlight - Should we highlight the statements in the console
    • SqlStatementLogger

      public SqlStatementLogger(boolean logToStdout, boolean format, boolean highlight, long logSlowQuery)
      Constructs a new SqlStatementLogger instance.
      Parameters:
      logToStdout - Should we log to STDOUT in addition to our internal logger?
      format - Should we format the statements in the console and log
      highlight - Should we highlight the statements in the console
      logSlowQuery - Should we logs query which executed slower than specified milliseconds. 0 - disabled.
  • Method Details

    • isLogToStdout

      public boolean isLogToStdout()

      Whether logging SQL to stdout is enabled.

      Note that SQL is always logged via logging using the org.hibernate.SQL category/logger name at DEBUG level regardless of this setting.

    • isFormat

      public boolean isFormat()
      Whether SQL is formatted prior to logging. Formatting makes the SQL "pretty" rather than one-line.
    • isHighlight

      public boolean isHighlight()
      Whether to apply highlighting via ASCII escape codes when logging to stdout.
    • getSlowQueryThreshold

      public long getSlowQueryThreshold()
      Number of milliseconds a query must take for execution to be considered slow. Used in logging slow Zero (0) indicates this is disabled.
    • getLogSlowQuery

      @Deprecated public long getLogSlowQuery()
      Deprecated.
    • logStatement

      public void logStatement(String statement)
      Log a SQL statement string.
      Parameters:
      statement - The SQL statement.
    • logStatement

      public void logStatement(String statement, org.hibernate.engine.jdbc.internal.Formatter formatter)
      Log a SQL statement string using the specified formatter
      Parameters:
      statement - The SQL statement.
      formatter - The formatter to use.
    • logSlowQuery

      public void logSlowQuery(String sql, long startTimeNanos, JdbcSessionContext context)
      Log a slow SQL query
      Parameters:
      sql - The SQL query.
      startTimeNanos - Start time in nanoseconds, or 0 if timing was not started.
    • setLogToStdout

      public void setLogToStdout(boolean logToStdout)
      Adjust whether to log to stdout.
    • setFormat

      public void setFormat(boolean format)
      Adjust whether to format SQL prior to logging.
    • setLogSlowQuery

      public void setLogSlowQuery(long threshold)
      Adjust the slow SQL threshold.