|
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 Additionally, since I am also only really interested in log
entries of type ERROR, I make use of the following method,
Where Object represents my <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 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(" 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]
