SK.gnome.dwarf.log
Class JDBCLogger

java.lang.Object
  extended bySK.gnome.dwarf.GenericService
      extended bySK.gnome.dwarf.thread.ThreadService
          extended bySK.gnome.dwarf.log.GenericLogger
              extended bySK.gnome.dwarf.log.JDBCLogger
All Implemented Interfaces:
Logger, java.lang.Runnable, Service

public class JDBCLogger
extends GenericLogger

The SQL database logger.

This logger writes log messages to a database table via the JDBC interface. The table must have the following structure:

 column         type          null     description
 ---------------------------------------------------------------
 datetime       datetime      no       date and time
 level          char(5)       no       logging level
 facility       varchar(20)   no       logging facility
 message        text          yes      message
 error          varchar(50)   yes      class name of the Java exception/error
 errormsg       text          yes      error message
 
The following sample SQL command can be used to create the appropriate table:
 CREATE TABLE log (
   datetime DATETIME NOT NULL,
   level CHAR(5) NOT NULL,
   facility varchar(2) NOT NULL,
   message TEXT,
   error VARCHAR(50),
   errormsg TEXT
 );
 


Field Summary
 
Fields inherited from class SK.gnome.dwarf.log.GenericLogger
facilities, levels, lock, LOG_FACILITY_ALL
 
Fields inherited from class SK.gnome.dwarf.thread.ThreadService
daemon, thread
 
Fields inherited from class SK.gnome.dwarf.GenericService
initParameters, parent
 
Fields inherited from interface SK.gnome.dwarf.Service
INITIALIZED, LOG_DEBUG, LOG_ERROR, LOG_FATAL, LOG_INFO, LOG_TRACE, LOG_WARN, LOG_XFER, SHUTDOWN, STARTED, STOPPED
 
Constructor Summary
JDBCLogger(java.lang.String name)
          Creates a new JDBCLogger.
 
Method Summary
 void init(Server parent)
          Initializes the service.
 void setDriver(java.lang.String value)
          Sets the JDBC driver class.
 void setPassword(java.lang.String value)
          Sets the JDBC connection password.
 void setTable(java.lang.String value)
          Sets the database table name.
 void setUrl(java.lang.String value)
          Sets the JDBC connection URL.
 void setUsername(java.lang.String value)
          Sets the JDBC connection username.
 void shutdown()
          Shuts down the service.
protected  boolean wouldLog(java.lang.String facility, LogLevel level)
          Decides whether the logger would log a message with the given loggging level and facility.
protected  void write(long time, java.lang.String facility, LogLevel level, java.lang.String message, java.lang.Throwable error)
          Writes the message to the database table.
 
Methods inherited from class SK.gnome.dwarf.log.GenericLogger
enableThread, getLastAccessed, log, log, loop, setFacilities, setLevels, setMarkInterval, setRepeatedInterval, start
 
Methods inherited from class SK.gnome.dwarf.thread.ThreadService
finish, run, setDaemon, stop
 
Methods inherited from class SK.gnome.dwarf.GenericService
getAuthenticator, getAuthFacility, getFullName, getInitParameter, getInitParameterNames, getLogFacility, getLogger, getName, getParameters, getPrincipal, getShutdownTimeout, getState, log, log, login, logout, setAuthFacility, setInitParameters, setLogFacility, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JDBCLogger

public JDBCLogger(java.lang.String name)
Creates a new JDBCLogger.

Method Detail

setDriver

public void setDriver(java.lang.String value)
Sets the JDBC driver class.

Parameters:
value - the driver class name

setUrl

public void setUrl(java.lang.String value)
Sets the JDBC connection URL.

Parameters:
value - the connection url

setUsername

public void setUsername(java.lang.String value)
Sets the JDBC connection username.

Parameters:
value - the username

setPassword

public void setPassword(java.lang.String value)
Sets the JDBC connection password.

Parameters:
value - the password

setTable

public void setTable(java.lang.String value)
Sets the database table name.

Parameters:
value - the table name

init

public void init(Server parent)
          throws ServiceException
Initializes the service.

It initializes also the JDBC connection and prepares the database resources.

Specified by:
init in interface Service
Overrides:
init in class GenericService
Throws:
ServiceException

shutdown

public void shutdown()
Shuts down the service.

It closes also the JDBC connection and frees the database resources.

Specified by:
shutdown in interface Service
Overrides:
shutdown in class GenericLogger

wouldLog

protected boolean wouldLog(java.lang.String facility,
                           LogLevel level)
Decides whether the logger would log a message with the given loggging level and facility.

It first checks whether the database connection has been initialized already and then calls the overriden wouldLog method and returns its result.

Overrides:
wouldLog in class GenericLogger
Parameters:
facility - the logging facility
level - the logging level
Returns:
true if the logger would log the message, false otherwise

write

protected void write(long time,
                     java.lang.String facility,
                     LogLevel level,
                     java.lang.String message,
                     java.lang.Throwable error)
Writes the message to the database table.

Note: if either the message or the error argument is null, the SQL NULL value will be stored to the corresponding column field.

Specified by:
write in class GenericLogger
Parameters:
time - the current time of the logged event
facility - the log facility
level - the log level
message - the message
error - the error (optional)
See Also:
GenericLogger.log(String, LogLevel, String), GenericLogger.log(String, LogLevel, String, Throwable)


Copyright (c) 1999-2005, Gnome Ltd. All rights reserved.