Class SqlStatementLogger


  • public class SqlStatementLogger
    extends java.lang.Object
    Centralize logging for SQL statements.
    • Constructor Summary

      Constructors 
      Constructor Description
      SqlStatementLogger()
      Constructs a new SqlStatementLogger instance.
      SqlStatementLogger​(boolean logToStdout, boolean format)
      Constructs a new SqlStatementLogger instance.
      SqlStatementLogger​(boolean logToStdout, boolean format, boolean highlight)
      Constructs a new SqlStatementLogger instance.
      SqlStatementLogger​(boolean logToStdout, boolean format, boolean highlight, long logSlowQuery)
      Constructs a new SqlStatementLogger instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      long getLogSlowQuery()  
      boolean isFormat()  
      boolean isLogToStdout()
      Are we currently logging to stdout?
      void logSlowQuery​(java.lang.String sql, long startTimeNanos)
      Log a slow SQL query
      void logSlowQuery​(java.sql.Statement statement, long startTimeNanos)
      Log a slow SQL query
      void logStatement​(java.lang.String statement)
      Log a SQL statement string.
      void logStatement​(java.lang.String statement, org.hibernate.engine.jdbc.internal.Formatter formatter)
      Log a SQL statement string using the specified formatter
      void setFormat​(boolean format)
      Deprecated.
      Will likely be removed: Should either become immutable or threadsafe.
      void setLogToStdout​(boolean logToStdout)
      Deprecated.
      Will likely be removed: Should either become immutable or threadsafe.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • 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 Detail

      • isLogToStdout

        public boolean isLogToStdout()
        Are we currently logging to stdout?
        Returns:
        True if we are currently logging to stdout; false otherwise.
      • setLogToStdout

        @Deprecated
        public void setLogToStdout​(boolean logToStdout)
        Deprecated.
        Will likely be removed: Should either become immutable or threadsafe.
        Enable (true) or disable (false) logging to stdout.
        Parameters:
        logToStdout - True to enable logging to stdout; false to disable.
      • isFormat

        public boolean isFormat()
      • setFormat

        @Deprecated
        public void setFormat​(boolean format)
        Deprecated.
        Will likely be removed: Should either become immutable or threadsafe.
      • getLogSlowQuery

        public long getLogSlowQuery()
      • logStatement

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

        public void logStatement​(java.lang.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​(java.sql.Statement statement,
                                 long startTimeNanos)
        Log a slow SQL query
        Parameters:
        statement - SQL statement.
        startTimeNanos - Start time in nanoseconds.
      • logSlowQuery

        public void logSlowQuery​(java.lang.String sql,
                                 long startTimeNanos)
        Log a slow SQL query
        Parameters:
        sql - The SQL query.
        startTimeNanos - Start time in nanoseconds.