Main: Whitepaper FAQ Examples JavaDoc Classloader Performance
Protomatter Software v1.1.8

com.protomatter.syslog
Class DatabaseLog

java.lang.Object
  |
  +--com.protomatter.syslog.BasicLogger
        |
        +--com.protomatter.syslog.DatabaseLog
All Implemented Interfaces:
Syslogger

public class DatabaseLog
extends BasicLogger

A logger that writes to a database. The tables it requires are:

  CREATE TABLE SYSLOG_LEVEL
  (
    SYSLOG_LEVEL         INT           PRIMARY KEY,
    SYSLOG_LEVEL_NAME    VARCHAR(8)    NOT NULL
  )

  CREATE TABLE SYSLOG_CHANNEL
  (
    CHANNEL       INT           PRIMARY KEY,
    CHANNEL_NAME  VARCHAR(128)  NOT NULL
  )

  CREATE TABLE SYSLOG_LOG
  (
    LOG_TIME      DATETIME      NOT NULL,
    SYSLOG_LEVEL  INT           NOT NULL
      REFERENCES SYSLOG_LEVEL(SYSLOG_LEVEL),
    HOST          VARCHAR(32)   NOT NULL,
    LOGGER        VARCHAR(64)   NOT NULL,
    CHANNEL       INT           NOT NULL
      REFERENCES SYSLOG_CHANNEL(CHANNEL),
    MESSAGE       VARCHAR(255)  NOT NULL,
    DETAIL        LONG          NULL,
    THREAD_NAME   VARCHAR(255)  NULL
  )
  

NOTE: To use this logger you must specify the "hostname" attribute for the <Syslog> tag in your configuration so that the hostname is correctly recorded.

Column widths are defined as follows:

HOST
getHostWidth() on format class.

LOGGER
getClassWidth() on format class.

THREAD_NAME
getThreadWidth() on format class.

MESSAGE
getMessageWidth() on this class.

DETAIL
getDetailWidth() on this class.

You may add a prefix to the names of each of the tables and specify that with the "jdbc.tablePrefix" property when initializing this logger. The default prefix is nothing.

You may have to change the type for SYSLOG_LOG.DETAIL to be something different for your database (VARCHAR2, LONG VARCHAR or LONG RAW, etc). It is written using an adapter class which implements the DatabaseLogStatementAdapter interface. Currently there are adapters for drivers which use the setString() , setAsciiStream(), or setCharacterStream() methods.

The SYSLOG_LEVEL table needs to contain the following rows:

The SYSLOG_CHANNEL table is populated automatically. Channel IDs start at 1 and go up from there.

See Also:
XML configuration class

Fields inherited from class com.protomatter.syslog.BasicLogger
formatter, policy, realPolicy
 
Constructor Summary
DatabaseLog()
          You will need to call the configure() method if you use this constructor.
 
Method Summary
 void flush()
          Flush the given logger's output.
 int getDetailWidth()
          Get the width of the message detail column.
 java.lang.String getDriver()
          Get the classname of the driver.
 int getMessageWidth()
          Get the width of the short message column.
 int getNumRetries()
          Get the number of retries before failure.
 java.util.Properties getProperties()
          Get the JDBC connection properties.
 DatabaseLogStatementAdapter getStatementAdapter()
          Get the database statement adapter.
 java.lang.String getTablePrefix()
          Get the table prefix.
 java.lang.String getURL()
          Get the JDBC URL.
 void initDatabase()
          (re)initialize the connection to the database.
 void log(SyslogMessage message)
          Log an entry to the log.
 void setDetailWidth(int width)
          Set the width of the message detail column.
 void setDriver(java.lang.String driver)
          Set the driver to use.
 void setMessageWidth(int width)
          Set the width of the short message column.
 void setNumRetries(int retries)
          Set the number of retries before failure.
 void setProperties(java.util.Properties props)
          Set the JDBC connection properties.
 void setStatementAdapter(DatabaseLogStatementAdapter adapter)
          Set the database statement adapter.
 void setTablePrefix(java.lang.String tablePrefix)
          Set the table prefix to use.
 void setTextFormatter(SyslogTextFormatter formatter)
          Set the log formatter object used by this logger.
 void setURL(java.lang.String url)
          Set the JDBC URL.
 void shutdown()
          Close the database connection and cleanup.
 
Methods inherited from class com.protomatter.syslog.BasicLogger
formatLogEntry, getName, getPolicy, getTextFormatter, isSuspended, mightLog, resetDateFormat, resume, setName, setPolicy, shouldLog, suspend
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseLog

public DatabaseLog()
You will need to call the configure() method if you use this constructor.
Method Detail

shutdown

public void shutdown()
Close the database connection and cleanup.

setDriver

public void setDriver(java.lang.String driver)
Set the driver to use.

setTablePrefix

public void setTablePrefix(java.lang.String tablePrefix)
Set the table prefix to use.

setURL

public void setURL(java.lang.String url)
Set the JDBC URL.

setNumRetries

public void setNumRetries(int retries)
Set the number of retries before failure.

setProperties

public void setProperties(java.util.Properties props)
Set the JDBC connection properties.

setStatementAdapter

public void setStatementAdapter(DatabaseLogStatementAdapter adapter)
Set the database statement adapter.

getStatementAdapter

public DatabaseLogStatementAdapter getStatementAdapter()
Get the database statement adapter.

getDriver

public java.lang.String getDriver()
Get the classname of the driver.

getTablePrefix

public java.lang.String getTablePrefix()
Get the table prefix.

getURL

public java.lang.String getURL()
Get the JDBC URL.

getNumRetries

public int getNumRetries()
Get the number of retries before failure.

getProperties

public java.util.Properties getProperties()
Get the JDBC connection properties.

setMessageWidth

public void setMessageWidth(int width)
Set the width of the short message column.

getMessageWidth

public int getMessageWidth()
Get the width of the short message column.

setDetailWidth

public void setDetailWidth(int width)
Set the width of the message detail column.

getDetailWidth

public int getDetailWidth()
Get the width of the message detail column.

initDatabase

public void initDatabase()
                  throws java.lang.Exception
(re)initialize the connection to the database.

log

public final void log(SyslogMessage message)
Description copied from interface: Syslogger
Log an entry to the log.

setTextFormatter

public void setTextFormatter(SyslogTextFormatter formatter)
Set the log formatter object used by this logger. DatabaseLog makes the extra requirement that this formatter be a subclass of the SimpleSyslogTextFormatter class.
Overrides:
setTextFormatter in class BasicLogger

flush

public void flush()
Description copied from interface: Syslogger
Flush the given logger's output.

Protomatter Software v1.1.8
Copyright 1998-2002 Nate Sammons

Protomatter Software v1.1.8 http://protomatter.sourceforge.net/1.1.8