org.apache.log4j.jdbcplus
Class JDBCLogger

java.lang.Object
  |
  +--org.apache.log4j.jdbcplus.JDBCLogger

public class JDBCLogger
extends Object

This class encapsulate the logic which is necessary to log into a table. Used by JDBCAppender

Since:
1.0
Version:
see jdbcappender.jar/META-INF/MANIFEST.MF for version information
Author:
Thomas Fenner, Danko Mannhaupt, many contributions by the community

Field Summary
protected  String layoutPartsDelimiter
          character to separate parts of layout if more than one part is to be used
protected  boolean usePreparedStatements
          Defines whether to use Prepared Statements instead of updateable result sets (default false)
 
Constructor Summary
JDBCLogger()
           
 
Method Summary
 void append(LoggingEvent event, Layout layout)
          Writes a message into the database table.
 void appendSQL(LoggingEvent aEvent, Layout layout)
          Writes a message into the database using a given sql-statement.
 void freeConnection()
          Description of the Method
 String getErrorMsg()
          Return the internal error message stored in instance variable msg.
 String getLayoutPartsDelimiter()
           
 String getProcedure()
           
 int getThrowableMaxChars()
           
 String getThrowableRepresentationFromLoggingEvent(LoggingEvent aLoggingEvent)
          Extracts Stack trace of Throwable contained in LogginEvent, if there is any
protected  String getTokenFromList(List tokenList, int index)
           
protected  List getTokenList(String t_layout)
          create token list from layout string
 boolean isCommit()
           
 boolean isConfigured()
          Return true, if this class is configured, else false.
 boolean isConnected()
          Return true, if this connection is open, else false.
 boolean isQuoteReplace()
           
 boolean isUsePreparedStatements()
           
 boolean prepareConnection()
          prepare connection
 boolean ready()
          Return true, if this class is ready to append(), else false.
 String replace(String source, int start, int end, int replacement)
          int-replacer
 String replace(String source, int start, int end, String replacement)
          String-replacer
 String replace(String source, String find, int replacement)
          int-replacer
 String replace(String source, String find, String replacement)
          String-replacer
 void setCommit(boolean b)
           
 void setConnection(Object obj)
          Sets a connection.
 void setLayoutPartsDelimiter(String c)
           
 void setLogType(String _name, int _logtype, Object _value)
          Sets a columns logtype (LogTypes) and value, which depends on that logtype.
 void setProcedure(String procedure, ArrayList columns)
           
 void setQuoteReplace(boolean b)
           
 void setSQL(String _sql)
          Configures this class, by storing and parsing the given sql-statement.
 void setSqlHandler(JDBCSqlHandler sqlHandler)
          Sets the SqlHandler attribute of the JDBCLogger object
 void setTable(String _table)
          Configures this class, by reading in the structure of the log-table Throws an exception, if an database-error occurs !
 void setThrowableMaxChars(int throwableMaxChars)
           
 void setUsePreparedStatements(boolean usePreparedStatements)
           
 void tryToFreeConnection()
          Calls freeConnection but catches all raising exceptions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

layoutPartsDelimiter

protected String layoutPartsDelimiter
character to separate parts of layout if more than one part is to be used


usePreparedStatements

protected boolean usePreparedStatements
Defines whether to use Prepared Statements instead of updateable result sets (default false)

Constructor Detail

JDBCLogger

public JDBCLogger()
Method Detail

setConnection

public void setConnection(Object obj)
                   throws Exception
Sets a connection. Throws an exception, if the connection is not open !

Parameters:
obj - The new Connection value
Throws:
Exception - Description of Exception

setSqlHandler

public void setSqlHandler(JDBCSqlHandler sqlHandler)
                   throws Exception
Sets the SqlHandler attribute of the JDBCLogger object

Parameters:
sqlHandler - The new SqlHandler value
Throws:
Exception - Description of Exception

setLogType

public void setLogType(String _name,
                       int _logtype,
                       Object _value)
                throws Exception
Sets a columns logtype (LogTypes) and value, which depends on that logtype. Throws an exception, if the given arguments arent correct !

Parameters:
_name - The new JDBCLogType value
_logtype - The new JDBCLogType value
_value - The new JDBCLogType value
Throws:
Exception - Description of Exception

setTable

public void setTable(String _table)
              throws Exception
Configures this class, by reading in the structure of the log-table Throws an exception, if an database-error occurs !

Parameters:
_table - Description of Parameter
Throws:
Exception - Description of Exception

setSQL

public void setSQL(String _sql)
            throws Exception
Configures this class, by storing and parsing the given sql-statement. Throws an exception, if somethings wrong !

Parameters:
_sql - Description of Parameter
Throws:
Exception - Description of Exception

isConfigured

public boolean isConfigured()
Return true, if this class is configured, else false.

Returns:
The Configured value

isConnected

public boolean isConnected()
Return true, if this connection is open, else false.

Returns:
The Connected value

getErrorMsg

public String getErrorMsg()
Return the internal error message stored in instance variable msg.

Returns:
The ErrorMsg value

freeConnection

public void freeConnection()
                    throws Exception
Description of the Method

Throws:
Exception - Description of Exception

tryToFreeConnection

public void tryToFreeConnection()
Calls freeConnection but catches all raising exceptions.

See Also:
freeConnection()

prepareConnection

public boolean prepareConnection()
                          throws Exception
prepare connection

Returns:
Description of the Returned Value
Throws:
Exception - Description of Exception

append

public void append(LoggingEvent event,
                   Layout layout)
            throws Exception
Writes a message into the database table. Throws an exception, if an database-error occurs !

Parameters:
event - the LoggingEvent to log
layout - layout to use for message
Throws:
Exception - Description of Exception

appendSQL

public void appendSQL(LoggingEvent aEvent,
                      Layout layout)
               throws Exception
Writes a message into the database using a given sql-statement. Throws an exception, if an database-error occurs !

Parameters:
layout - layout to use for message
Throws:
Exception - Description of Exception

getTokenFromList

protected String getTokenFromList(List tokenList,
                                  int index)
                           throws Exception
Parameters:
tokenList -
index - list index, 1-based.
Returns:
(index-1)'th element in list
Throws:
Exception

getTokenList

protected List getTokenList(String t_layout)
create token list from layout string

Parameters:
t_layout -
Returns:
list of layout parts

ready

public boolean ready()
Return true, if this class is ready to append(), else false. When not ready, a reason-String is stored in the instance-variable msg.

Returns:
Description of the Returned Value

replace

public String replace(String source,
                      String find,
                      String replacement)
String-replacer

Parameters:
source - Description of Parameter
find - Description of Parameter
replacement - Description of Parameter
Returns:
Description of the Returned Value

replace

public String replace(String source,
                      String find,
                      int replacement)
int-replacer

Parameters:
source - Description of Parameter
find - Description of Parameter
replacement - Description of Parameter
Returns:
Description of the Returned Value

replace

public String replace(String source,
                      int start,
                      int end,
                      String replacement)
String-replacer

Parameters:
source - Description of Parameter
start - Description of Parameter
end - Description of Parameter
replacement - Description of Parameter
Returns:
Description of the Returned Value

replace

public String replace(String source,
                      int start,
                      int end,
                      int replacement)
int-replacer

Parameters:
source - Description of Parameter
start - Description of Parameter
end - Description of Parameter
replacement - Description of Parameter
Returns:
Description of the Returned Value

getThrowableRepresentationFromLoggingEvent

public String getThrowableRepresentationFromLoggingEvent(LoggingEvent aLoggingEvent)
Extracts Stack trace of Throwable contained in LogginEvent, if there is any

Parameters:
aLoggingEvent - logging event
Returns:
stack trace of throwable

isCommit

public boolean isCommit()
Returns:
docommit attribute

setCommit

public void setCommit(boolean b)
Parameters:
b -

isQuoteReplace

public boolean isQuoteReplace()
Returns:
quoteReplace

setQuoteReplace

public void setQuoteReplace(boolean b)
Parameters:
b -

getLayoutPartsDelimiter

public String getLayoutPartsDelimiter()
Returns:
layoutPartsDelimiter

setLayoutPartsDelimiter

public void setLayoutPartsDelimiter(String c)
Parameters:
c -

isUsePreparedStatements

public boolean isUsePreparedStatements()
Returns:
Returns the usePreparedStatements.

setUsePreparedStatements

public void setUsePreparedStatements(boolean usePreparedStatements)
Parameters:
usePreparedStatements - The usePreparedStatements to set.

getProcedure

public String getProcedure()
Returns:
Returns the procedure.

setProcedure

public void setProcedure(String procedure,
                         ArrayList columns)
                  throws Exception
Parameters:
procedure - The procedure to set.
columns - columns
Exception

getThrowableMaxChars

public int getThrowableMaxChars()
Returns:
Returns the throwableMaxChars.

setThrowableMaxChars

public void setThrowableMaxChars(int throwableMaxChars)
Parameters:
throwableMaxChars - The throwableMaxChars to set.


Copyright 2000-2004 Apache Software Foundation.