public class DBAppender extends AppenderSkeleton implements 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.
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
Constructor and Description |
---|
DBAppender() |
Modifier and Type | Method and Description |
---|---|
void |
activateOptions() |
protected void |
append(LoggingEvent event) |
void |
close() |
ConnectionSource |
getConnectionSource() |
boolean |
getLocationInfo()
Returns value of the LocationInfo property which determines whether
caller's location info is written to the database.
|
boolean |
parseUnrecognizedElement(org.w3c.dom.Element element,
java.util.Properties props) |
boolean |
requiresLayout()
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.
|
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold
public void activateOptions()
activateOptions
in interface OptionHandler
activateOptions
in class AppenderSkeleton
public ConnectionSource getConnectionSource()
public void setConnectionSource(ConnectionSource connectionSource)
connectionSource
- The connectionSource to set.protected void append(LoggingEvent event)
append
in class AppenderSkeleton
public boolean getLocationInfo()
public void setLocationInfo(boolean locationInfo)
public boolean requiresLayout()
requiresLayout
in interface Appender
public boolean parseUnrecognizedElement(org.w3c.dom.Element element, java.util.Properties props) throws java.lang.Exception
parseUnrecognizedElement
in interface UnrecognizedElementHandler
java.lang.Exception
Copyright © 2006-2019 OPS4J - Open Participation Software for Java. All Rights Reserved.