Well, there is not a torque appender that I know of.  However, there is
already a JDBC appender.  I would suggest that you explore that route
before writing your own version that uses Torque.


--------------------------------------------
Quinton McCombs
NequalsOne - HealthCare marketing tools
mailto:[EMAIL PROTECTED]
http://www.NequalsOne.com 
-----Original Message-----
From: soteri panagou [mailto:[EMAIL PROTECTED] 
Sent: Monday, June 02, 2003 8:39 PM
To: [EMAIL PROTECTED]
Subject: inital log4j torque adapter


Hi all.
 
Dunno if this is the correct mailing list for this, but I have done an
initial impl of a log4j log appender. Also, please let me know if there
is already something like this, (hopefully I�m not reinventing the
wheel)
 
The primary reason I want it is to trap exceptions to a database table:
The assumption I make here is that you may have a OM peer that
represents your own log entry in your log table. The idea is to extend
the abstract TorqueLogger class (in my case MideLogger) that will handle
the insertion. 
 
Additionally, since I am also only really interested in log entries of
type ERROR, I make use of the following method, 
 
org.apache.log4j.Category:: void error(Object message, Throwable t)
 
Where Object represents my OM class (and not a String as is usually the
case I think) (generated from the following xml fragment);
 
            <table name="LogEntry">
            <!-- used by the log4j subsystem to log exceptions that
occur --> 
                        <column name="ID" primaryKey="true"
required="true" type="INTEGER" javaType="object"/>
                        <column name="LogLevel" required="true"
size="20">
                                    <!�represents the type of log entry:
WARNING, INFO etc �
                        </column>
                        <column name="MYFIRSTCUSTOMFIELD" size="50" />
                        <column name="MYSECONDCUSTOMFIELD" size="80" />
                        <column name="Origin" size="200">
                                    <!�the class name, method, and line
number the the log message was generated from �
                        </column>
                        <column name="Message" size="3000" >
                                    <!�the actual exception stack trace
�
                        </column>
                        <column name="WhenOccurred" type="TIMESTAMP" />
            </table>
 
This is the architecture (See attachments): 
a)       TorqueAppender.java � implements log4j�s AppenderSkeleton, 
b)       TorqueLogger.java � the base abstract class that consumes the
message and interacts with the specified OM class to persist it to the
torque database
c)       MideLogger.java � my specific logger class that casts the
Object to a LogEntry class, populates it and then finally persists it by
calling the save() method
 
So within my application, I do the following:
 
            Logger cat = Logger.getLogger("TORQUE");
            LogEntry l1 = new LogEntry();
            l1.setClientID("BEAUMONT");
            l1.setMsgID("MsgID");
            cat.error((Object) l1, new java.io.IOException("MOO"));
 
The result is an entry added to my LogEntry table.
 
My log4j.properties file has the following entries: 
 
###
# configure the logger/appender
###
log4j.logger.TORQUE=ERROR,T
log4j.appender.T=com.mide.log.TorqueAppender
 
######
# this property the precise Torque logger that must be used.
######
log4j.appender.T.logger=com.mide.log.MideLogger           
 
#######
# this property defines the max size of
# exception stack traces, if exceeded the 
# MideLogger truncates it.
########
log4j.appender.T.maxmsgsize=700          
 

Please lemme know what you guys think
 
Steri


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to