Class DBAppender
- All Implemented Interfaces:
org.apache.log4j.Appender
,org.apache.log4j.spi.OptionHandler
,org.apache.log4j.xml.UnrecognizedElementHandler
If the JDBC driver you are using supports the
Statement.getGeneratedKeys()
method introduced in JDBC 3.0
specification, then you are all set. Otherwise, there must be an
SQLDialect
appropriate for your database system. Currently, we have
dialects for PostgreSQL, MySQL, Oracle and MsSQL. As mentioed previously, an
SQLDialect is required only if the JDBC driver for your database system does
not support the getGeneratedKeys
method.
RDBMS | supports getGeneratedKeys() method |
specific SQLDialect support |
---|---|---|
PostgreSQL | NO | present and used |
MySQL | YES | present, but not actually needed or used |
Oracle | YES | present, but not actually needed or used |
DB2 | YES | not present, and not needed or used |
MsSQL | YES | not present, and not needed or used |
HSQL | NO | present and used |
Performance: Experiments show that writing a single event into the database takes approximately 50 milliseconds, on a "standard" PC. If pooled connections are used, this figure drops to under 10 milliseconds. Note that most JDBC drivers already ship with connection pooling support.
Configuration DBAppender can be configured programmatically, or using
JoranConfigurator
. Example
scripts can be found in the tests/input/db directory.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) boolean
(package private) boolean
(package private) ConnectionSource
(package private) static final String
(package private) static final String
(package private) static final String
(package private) boolean
(package private) SQLDialect
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
protected void
append
(org.apache.log4j.spi.LoggingEvent event) void
close()
boolean
Returns value of the LocationInfo property which determines whether caller's location info is written to the database.boolean
parseUnrecognizedElement
(Element element, Properties props) boolean
Gets whether appender requires a layout.void
setConnectionSource
(ConnectionSource connectionSource) void
setLocationInfo
(boolean locationInfo) If true, the information written to the database will include caller's location information.Methods inherited from class org.apache.log4j.AppenderSkeleton
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold
-
Field Details
-
insertPropertiesSQL
- See Also:
-
insertExceptionSQL
- See Also:
-
insertSQL
-
connectionSource
ConnectionSource connectionSource -
cnxSupportsGetGeneratedKeys
boolean cnxSupportsGetGeneratedKeys -
cnxSupportsBatchUpdates
boolean cnxSupportsBatchUpdates -
sqlDialect
SQLDialect sqlDialect -
locationInfo
boolean locationInfo
-
-
Constructor Details
-
DBAppender
public DBAppender()
-
-
Method Details
-
activateOptions
public void activateOptions()- Specified by:
activateOptions
in interfaceorg.apache.log4j.spi.OptionHandler
- Overrides:
activateOptions
in classorg.apache.log4j.AppenderSkeleton
-
getConnectionSource
- Returns:
- Returns the connectionSource.
-
setConnectionSource
- Parameters:
connectionSource
- The connectionSource to set.
-
append
protected void append(org.apache.log4j.spi.LoggingEvent event) - Specified by:
append
in classorg.apache.log4j.AppenderSkeleton
-
close
public void close()- Specified by:
close
in interfaceorg.apache.log4j.Appender
-
getLocationInfo
public boolean getLocationInfo()Returns value of the LocationInfo property which determines whether caller's location info is written to the database. -
setLocationInfo
public void setLocationInfo(boolean locationInfo) If true, the information written to the database will include caller's location information. Due to performance concerns, by default no location information is written to the database. -
requiresLayout
public boolean requiresLayout()Gets whether appender requires a layout.- Specified by:
requiresLayout
in interfaceorg.apache.log4j.Appender
- Returns:
- false
-
parseUnrecognizedElement
- Specified by:
parseUnrecognizedElement
in interfaceorg.apache.log4j.xml.UnrecognizedElementHandler
- Throws:
Exception
-