Class SqlStatementLogger
java.lang.Object
org.hibernate.engine.jdbc.spi.SqlStatementLogger
- All Implemented Interfaces:
Serializable, Service
Centralize logging for SQL statements, with some configuration:
Some of these configuration values can be adjusted at runtime.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newSqlStatementLoggerinstance.SqlStatementLogger(boolean logToStdout, boolean format) Constructs a newSqlStatementLoggerinstance.SqlStatementLogger(boolean logToStdout, boolean format, boolean highlight) Constructs a newSqlStatementLoggerinstance.SqlStatementLogger(boolean logToStdout, boolean format, boolean highlight, long logSlowQuery) Constructs a newSqlStatementLoggerinstance. -
Method Summary
Modifier and TypeMethodDescriptionlongDeprecated.longNumber of milliseconds a query must take for execution to be considered slow.booleanisFormat()Whether SQL is formatted prior to logging.booleanWhether to apply highlighting via ASCII escape codes when logging to stdout.booleanWhether logging SQL to stdout is enabled.voidlogSlowQuery(String sql, long startTimeNanos, JdbcSessionContext context) Log a slow SQL queryvoidlogStatement(String statement) Log a SQL statement string.voidlogStatement(String statement, org.hibernate.engine.jdbc.internal.Formatter formatter) Log a SQL statement string using the specified formattervoidsetFormat(boolean format) Adjust whether to format SQL prior to logging.voidsetLogSlowQuery(long threshold) Adjust the slow SQL threshold.voidsetLogToStdout(boolean logToStdout) Adjust whether to log to stdout.
-
Constructor Details
-
SqlStatementLogger
public SqlStatementLogger()Constructs a newSqlStatementLoggerinstance. -
SqlStatementLogger
public SqlStatementLogger(boolean logToStdout, boolean format) Constructs a newSqlStatementLoggerinstance.- 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 newSqlStatementLoggerinstance.- Parameters:
logToStdout- Should we log to STDOUT in addition to our internal logger?format- Should we format the statements in the console and loghighlight- Should we highlight the statements in the console
-
SqlStatementLogger
public SqlStatementLogger(boolean logToStdout, boolean format, boolean highlight, long logSlowQuery) Constructs a newSqlStatementLoggerinstance.- Parameters:
logToStdout- Should we log to STDOUT in addition to our internal logger?format- Should we format the statements in the console and loghighlight- Should we highlight the statements in the consolelogSlowQuery- 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.SQLcategory/logger name atDEBUGlevel 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.UsegetSlowQueryThreshold()instead. -
logStatement
Log a SQL statement string.- Parameters:
statement- The SQL statement.
-
logStatement
Log a SQL statement string using the specified formatter- Parameters:
statement- The SQL statement.formatter- The formatter to use.
-
logSlowQuery
Log a slow SQL query- Parameters:
sql- The SQL query.startTimeNanos- Start time in nanoseconds, or0if 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.
-
getSlowQueryThreshold()instead.