public class Log4j2SpyLogDelegator extends Object implements SpyLogDelegator
Differences in implementation and behavior as compared to Slf4jSpyLogDelegator
:
Slf4jSpyLogDelegator
:
one for logging all spy logging events
("log4jdbc.log4j2", see LOGGER
attribute),
another one for logging debugging within log4jdbc itself
("log4jdbc.debug" logger, see DEBUGLOGGER
attribute,
or Slf4jSpyLogDelegator
debugLogger
attribute).
Marker
CONNECTION_MARKER
, named "LOG4JDBC_CONNECTION"
Marker
RESULTSET_MARKER
, named "LOG4JDBC_RESULTSET",
a child of the Marker
JDBC_MARKER
, named "LOG4JDBC_JDBC"
Marker
RESULTSETTABLE_MARKER
, named "LOG4JDBC_RESULTSETTABLE",
a child of the Marker
RESULTSET_MARKER
, named "LOG4JDBC_RESULTSET"
Marker
AUDIT_MARKER
, named "LOG4JDBC_AUDIT",
a child of the Marker
JDBC_MARKER
, named "LOG4JDBC_JDBC"
JDBC_MARKER
and CONNECTION_MARKER
are children of
NON_STATEMENT_MARKER
, named "LOG4JDBC_NON_STATEMENT".
This is to easily reproduce standard log4jdbc loggers behavior,
and behavior of log4jdbc-remix.
Slf4jSpyLogDelegator
sqlOnlyLogger
attribute)
is not reproduced.
This is for the will of keeping one single logger, while the logging of spy events
immediately, before the action is executed and before knowing the execution time,
would definitely require another logger.
Also, execution time seems to be an always-useful information to get.
sqlOccured(Spy, String, String)
is not implemented.
Marker
s, some options configured
in the log4jdbc properties file can be set directly in the log4j2 configuration file:
Marker
SELECT_MARKER
,
named "LOG4JDBC_SELECT"
Marker
INSERT_MARKER
,
named "LOG4JDBC_INSERT"
Marker
UPDATE_MARKER
,
named "LOG4JDBC_UPDATE"
Marker
DELETE_MARKER
,
named "LOG4JDBC_DELETE"
Marker
CREATE_MARKER
,
named "LOG4JDBC_CREATE"
Marker
s are all children of the Marker
SQL_MARKER
, named "LOG4JDBC_SQL".
These properties can also be set through the log4jdbc properties file.
They would have priority over the Marker
s.
SpyLogDelegator
,
and the classes Slf4jSpyLogDelegator
, DriverSpy
,
ConnectionSpy
, SpyLogFactory
,
StatementSpy
and PreparedStatementSpy
have been modified. See their corresponding javadoc for information about the changes.
LOGGER
,
DEBUGLOGGER
,
Slf4jSpyLogDelegator
,
SpyLogDelegator
,
DriverSpy
,
SpyLogFactory
Constructor and Description |
---|
Log4j2SpyLogDelegator() |
Modifier and Type | Method and Description |
---|---|
void |
connectionAborted(Spy spy,
long execTime)
Called whenever a connection spy is aborted.
|
void |
connectionClosed(Spy spy,
long execTime)
Called whenever a connection spy is closed.
|
void |
connectionOpened(Spy spy,
long execTime)
Called whenever a new connection spy is created.
|
void |
constructorReturned(Spy spy,
String constructionInfo)
Called when a spied upon object is constructed.
|
void |
debug(String msg)
Log a Setup and/or administrative log message for log4jdbc.
|
void |
exceptionOccured(Spy spy,
String methodCall,
Exception e,
String sql,
long execTime)
Called when a spied upon method throws an Exception.
|
boolean |
isJdbcLoggingEnabled()
Determine if any of the jdbc or sql loggers are turned on.
|
boolean |
isResultSetCollectionEnabled()
Determine whether the logger is expecting results sets to be collected
|
boolean |
isResultSetCollectionEnabledWithUnreadValueFillIn()
Determine whether the logger is expecting results sets to be collected
AND any unread result set values read explicitly
|
void |
methodReturned(Spy spy,
String methodCall,
String returnMsg)
Called when spied upon method call returns.
|
void |
resultSetCollected(ResultSetCollector resultSetCollector)
Called whenever result set has been collected.
|
void |
sqlOccurred(Spy spy,
String methodCall,
String sql)
Special call that is called only for JDBC method calls that contain SQL.
|
void |
sqlTimingOccurred(Spy spy,
long execTime,
String methodCall,
String sql)
Similar to sqlOccured, but reported after SQL executes and used to report timing stats on the SQL
|
public boolean isJdbcLoggingEnabled()
SpyLogDelegator
isJdbcLoggingEnabled
in interface SpyLogDelegator
public void exceptionOccured(Spy spy, String methodCall, Exception e, String sql, long execTime)
SpyLogDelegator
exceptionOccured
in interface SpyLogDelegator
spy
- the Spy wrapping the class that threw an Exception.methodCall
- a description of the name and call parameters of the method generated the Exception.e
- the Exception that was thrown.sql
- optional sql that occured just before the exception occured.execTime
- optional amount of time that passed before an exception was thrown when sql was being executed.
caller should pass -1 if not usedpublic void methodReturned(Spy spy, String methodCall, String returnMsg)
SpyLogDelegator
methodReturned
in interface SpyLogDelegator
spy
- the Spy wrapping the class that called the method that returned.methodCall
- a description of the name and call parameters of the method that returned.returnMsg
- return value converted to a String for integral types, or String representation for Object
return types this will be null for void return types.public void constructorReturned(Spy spy, String constructionInfo)
SpyLogDelegator
constructorReturned
in interface SpyLogDelegator
spy
- the Spy wrapping the class that called the method that returned.constructionInfo
- information about the object constructionpublic void sqlOccurred(Spy spy, String methodCall, String sql)
SpyLogDelegator
sqlOccurred
in interface SpyLogDelegator
spy
- the Spy wrapping the class where the SQL occurred.methodCall
- a description of the name and call parameters of the method that generated the SQL.sql
- sql that occurred.public void sqlTimingOccurred(Spy spy, long execTime, String methodCall, String sql)
SpyLogDelegator
sqlTimingOccurred
in interface SpyLogDelegator
spy
- the Spy wrapping the class where the SQL occurred.execTime
- how long it took the sql to run, in msec.methodCall
- a description of the name and call parameters of the method that generated the SQL.sql
- sql that occurred.public void connectionOpened(Spy spy, long execTime)
SpyLogDelegator
connectionOpened
in interface SpyLogDelegator
spy
- ConnectionSpy that was created.execTime
- A long
defining the time elapsed to open the connection in ms
(useful information, as a connection might take some time to be opened sometimes).
Caller should pass -1 if not used or unknown.public void connectionClosed(Spy spy, long execTime)
SpyLogDelegator
connectionClosed
in interface SpyLogDelegator
spy
- ConnectionSpy
that was closed.execTime
- A long
defining the time elapsed to close the connection in ms
(useful information, as a connection might take some time to be closed sometimes).
Caller should pass -1 if not used or unknown.public void connectionAborted(Spy spy, long execTime)
SpyLogDelegator
connectionAborted
in interface SpyLogDelegator
spy
- ConnectionSpy
that was aborted.execTime
- A long
defining the time elapsed to abort the connection in ms
(useful information, as a connection might take some time to be aborted sometimes).
Caller should pass -1 if not used or unknown.public void debug(String msg)
SpyLogDelegator
debug
in interface SpyLogDelegator
msg
- message to log.public boolean isResultSetCollectionEnabled()
SpyLogDelegator
isResultSetCollectionEnabled
in interface SpyLogDelegator
public boolean isResultSetCollectionEnabledWithUnreadValueFillIn()
SpyLogDelegator
isResultSetCollectionEnabledWithUnreadValueFillIn
in interface SpyLogDelegator
public void resultSetCollected(ResultSetCollector resultSetCollector)
SpyLogDelegator
next()
method of the spied ResultSet
return false
meaning that its end is reached.
It will be also called if the ResultSet
is closed.resultSetCollected
in interface SpyLogDelegator
ResultSetSpy
,
DefaultResultSetCollector
Copyright © 2013 Bgee - Swiss Institute of Bioinformatics. All Rights Reserved.