Top Description Fields Constructors Methods
org.hibernate.engine.jdbc.spi

public Class SqlStatementLogger

extends Object
Class Inheritance
Imports
org.hibernate.engine.jdbc.internal.FormatStyle, .Formatter, org.hibernate.internal.CoreLogging, org.hibernate.internal.build.AllowSysOut, org.jboss.logging.Logger, java.sql.Statement, java.util.concurrent.TimeUnit

Centralize logging for SQL statements.
Author
Steve Ebersole

Field Summary

Modifier and TypeField and Description
private boolean
private final boolean
private static final Logger
private static final Logger
private final long
logSlowQuery

Configuration value that indicates slow query.

private boolean

Constructor Summary

AccessConstructor and Description
public
SqlStatementLogger()

Constructs a new SqlStatementLogger instance.

public
SqlStatementLogger(boolean
Should we log to STDOUT in addition to our internal logger.
logToStdout
,
boolean
Should we format the statements in the console and log
format
)

Constructs a new SqlStatementLogger instance.

public
SqlStatementLogger(boolean
Should we log to STDOUT in addition to our internal logger.
logToStdout
,
boolean
Should we format the statements in the console and log
format
,
boolean
Should we highlight the statements in the console
highlight
)

Constructs a new SqlStatementLogger instance.

public
SqlStatementLogger(boolean
Should we log to STDOUT in addition to our internal logger.
logToStdout
,
boolean
Should we format the statements in the console and log
format
,
boolean
Should we highlight the statements in the console
highlight
,
long
Should we logs query which executed slower than specified milliseconds. 0 - disabled.
logSlowQuery
)

Constructs a new SqlStatementLogger instance.

Method Summary

Modifier and TypeMethod and Description
public long
public boolean
public boolean

Returns:

True if we are currently logging to stdout; false otherwise.
isLogToStdout
()

Are we currently logging to stdout?

public void
logSlowQuery(Statement
SQL statement.
statement
,
long
Start time in nanoseconds.
startTimeNanos
)

Log a slow SQL query

public void
logSlowQuery(String
The SQL query.
sql
,
long
Start time in nanoseconds.
startTimeNanos
)

Log a slow SQL query

public void
logStatement(String
The SQL statement.
statement
)

Log a SQL statement string.

public void
logStatement(String
The SQL statement.
statement
,
Formatter
The formatter to use.
formatter
)

Log a SQL statement string using the specified formatter

public void
setFormat(boolean format)

Deprecated Will likely be removed: Should either become immutable or threadsafe.
public void
setLogToStdout(boolean
True to enable logging to stdout; false to disable.
logToStdout
)

Deprecated Will likely be removed: Should either become immutable or threadsafe.
Enable (true) or disable (false) logging to stdout.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

formatback to summary
private boolean format
highlightback to summary
private final boolean highlight
LOGback to summary
private static final Logger LOG
LOG_SLOWback to summary
private static final Logger LOG_SLOW
logSlowQueryback to summary
private final long logSlowQuery

Configuration value that indicates slow query. (In milliseconds) 0 - disabled.

logToStdoutback to summary
private boolean logToStdout

Constructor Detail

SqlStatementLoggerback to summary
public SqlStatementLogger()

Constructs a new SqlStatementLogger instance.

SqlStatementLoggerback to summary
public SqlStatementLogger(boolean logToStdout, boolean format)

Constructs a new SqlStatementLogger instance.

Parameters
logToStdout:boolean

Should we log to STDOUT in addition to our internal logger.

format:boolean

Should we format the statements in the console and log

SqlStatementLoggerback to summary
public SqlStatementLogger(boolean logToStdout, boolean format, boolean highlight)

Constructs a new SqlStatementLogger instance.

Parameters
logToStdout:boolean

Should we log to STDOUT in addition to our internal logger.

format:boolean

Should we format the statements in the console and log

highlight:boolean

Should we highlight the statements in the console

SqlStatementLoggerback to summary
public SqlStatementLogger(boolean logToStdout, boolean format, boolean highlight, long logSlowQuery)

Constructs a new SqlStatementLogger instance.

Parameters
logToStdout:boolean

Should we log to STDOUT in addition to our internal logger.

format:boolean

Should we format the statements in the console and log

highlight:boolean

Should we highlight the statements in the console

logSlowQuery:long

Should we logs query which executed slower than specified milliseconds. 0 - disabled.

Method Detail

getLogSlowQueryback to summary
public long getLogSlowQuery()
isFormatback to summary
public boolean isFormat()
isLogToStdoutback to summary
public boolean isLogToStdout()

Are we currently logging to stdout?

Returns:boolean

True if we are currently logging to stdout; false otherwise.

logSlowQueryback to summary
public void logSlowQuery(Statement statement, long startTimeNanos)

Log a slow SQL query

Parameters
statement:Statement

SQL statement.

startTimeNanos:long

Start time in nanoseconds.

logSlowQueryback to summary
public void logSlowQuery(String sql, long startTimeNanos)

Log a slow SQL query

Parameters
sql:String

The SQL query.

startTimeNanos:long

Start time in nanoseconds.

Annotations
@AllowSysOut
logStatementback to summary
public void logStatement(String statement)

Log a SQL statement string.

Parameters
statement:String

The SQL statement.

logStatementback to summary
public void logStatement(String statement, Formatter formatter)

Log a SQL statement string using the specified formatter

Parameters
statement:String

The SQL statement.

formatter:Formatter

The formatter to use.

Annotations
@AllowSysOut
setFormatback to summary
public void setFormat(boolean format)

Deprecated

Will likely be removed: Should either become immutable or threadsafe.

Annotations
@Deprecated
setLogToStdoutback to summary
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:boolean

True to enable logging to stdout; false to disable.

Annotations
@Deprecated