org.jscience.util.logging
Class JDBCLogWriter
java.lang.Object
org.jscience.util.logging.AbstractLogWriter
org.jscience.util.logging.JDBCLogWriter
- All Implemented Interfaces:
- Filter<LogEntry>, LogWriter
public class JDBCLogWriter
- extends AbstractLogWriter
JDBCLogWriter provides a LogWriter that writes to a java.sql.Connection.
It requires a LogEntryFormatter that maps the fields from the LogEntry
object to the fields of a table. The required LogEntryFormatter's
format(LogEntry) would return an Object[] that contains the
values that are to be inserted into the table. This implementation is only
suitable for those implementations where it is sufficient to store the
LogEntry data into a single row of a single table. Below is some sample
code that demonstrates how a LogEntryFormatter could be implemented to be
used with this class.
public Object format (LogEntry entry) {
Object[] value = new Object[10];
value[0] = new Timestamp(entry.getTime());
value[1] = entry.getLevel().toString();
value[2] = entry.getMessage(); value[3] = entry.getSourceClassName();
value[4] = entry.getThreadName();
value[5] = (entry.getThrown() == null)? null : entry.getThrown().getMessage();
value[6] = (entry.getThrown() == null)? null : entry.getThrown().getClass().getName();
if (entry.getParameters() != null) {
value[7] = (entry.getParameters()[0] == null)? null : entry.getParameters()[0].toString();
value[8] = (entry.getParameters()[0] == null)? null : entry.getParameters()[0].toString();
value[9] = (entry.getParameters()[0] == null)? null : entry.getParameters()[0].toString();
} for (int i = 0; i < value.length; i++) {
if (value[i] == null) value[i] = ""; } return value;}The
above code example would work with a table that contains 10 data fields
that would take the above returned array accordingly.
- See Also:
JDBC.insert(Connection,String,Object[])
|
Constructor Summary |
JDBCLogWriter(java.sql.Connection con,
java.lang.String tableName,
LogEntryFormatter formatter)
requires a formatter that will split log entries in an object array
which corresponds to the fields in the given table. |
|
Method Summary |
java.sql.Connection |
getConnection()
DOCUMENT ME! |
void |
writeLogEntry(java.lang.Object pattern)
the entry is split into an object array by the formatter which
is then inserted into the table. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
JDBCLogWriter
public JDBCLogWriter(java.sql.Connection con,
java.lang.String tableName,
LogEntryFormatter formatter)
- requires a formatter that will split log entries in an object array
which corresponds to the fields in the given table.
- See Also:
JDBC.insert(Connection,String,Object[])
writeLogEntry
public void writeLogEntry(java.lang.Object pattern)
throws LogException
- the entry is split into an object array by the formatter which
is then inserted into the table. For more sophisticated storage that
requires more than one table (if e.g. a variable number of parameters
are to be stored in a separate table) a different implementation would
be required.
- Specified by:
writeLogEntry in class AbstractLogWriter
- Parameters:
pattern - DOCUMENT ME!
- Throws:
LogException - DOCUMENT ME!- See Also:
JDBC.insert(Connection,String,Object[])
getConnection
public java.sql.Connection getConnection()
- DOCUMENT ME!
- Returns:
- DOCUMENT ME!