You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by James Stauffer <js...@spscommerce.com> on 2004/05/06 20:39:45 UTC

Logging stack trace to a Database

I would like my log messages logged to a Database with the stack trace.  It
appears DBAppender (in 1.3) doesn't do that.  What is the best way to
accomplish that?  I am willing to do the coding.  Two ideas that I had are:

1. Change DBAppender to support another column for the stack trace.
   Pro: Should be easy to do.
   Con: Would everyone want the stack trace?  
	Right now there is no way for a user to choose what they want so the
user couldn't decide to not get the stack trace.

2. Make a new Database Appender (let's call it DBAppender2 for now).
   Pro: Could code to allow the user to decide what goes in the Database.  
	The autoincrementing sequence issue wouldn't matter in log4j
(sqlDialect.getSelectInsertId()). 
	The only mandatory option would be "TableName".  
	All other options would be interpreted as column names with the
value of the option being passed through the layout class. Example:
  <param name="TableName" value="logging_event" />
  <param name="message" value="%m" />
  <param name="catagory" value="%c" />
  <param name="Thread" value="%t" />
  <param name="machine" value="machine" /><!-- different machines would have
different values here in their log4j.xml -->
  <param name="Priority" value="%p" />
  <param name="Time" value="%d" />
  <param name="Short_Message" value="%p @ %d: %m" />
  <param name="URL" value="%X{url}" />
  <param name="stack" value="%throwable" />

  Con: Lots more coding.  
	More complex.
	Stack traces can be long so how would that be handled so that
overflow wouldn't prevent logging.
	Are arbitrary options supported?  
	Would everyting have to go in the Database as a string?
	How would dates and sequence numbers be handled?
	Could we treat the value as a date if(value.startsWith(%d) ||
(value.startsWith(%d{) && value.indexOf("}") == value.length()))?


Comments?


James Stauffer
 

Re: Logging stack trace to a Database

Posted by Raymond DeCampo <rd...@twcny.rr.com>.
James,

Please see the PreparedStatementAppender class available in the 
log4j-sandbox via CVS at apache.org.  It does support logging the stack 
trace to the database.

Ceki has indicated that some form of this class will likely be included 
in log4j version 1.3.  Now will be a good time for you to provide 
feedback on how the class meets your needs or to supply patches if you 
would like to make improvements.

Ray

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Re: Logging stack trace to a Database

Posted by Ceki Gülcü <ce...@qos.ch>.
James,

To support exceptions, create a new table and handle the exception data in 
a similar way to the insertion of  MDC properties.

Does this help?

At 08:39 PM 5/6/2004, James Stauffer wrote:

>I would like my log messages logged to a Database with the stack 
>trace.  It appears DBAppender (in 1.3) doesn't do that.  What is the best 
>way to accomplish that?  I am willing to do the coding.  Two ideas that I 
>had are:
>
>1. Change DBAppender to support another column for the stack trace.
>    Pro: Should be easy to do.
>    Con: Would everyone want the stack trace?
>         Right now there is no way for a user to choose what they want so 
> the user couldn't decide to not get the stack trace.
>
>2. Make a new Database Appender (let's call it DBAppender2 for now).
>    Pro: Could code to allow the user to decide what goes in the Database.
>         The autoincrementing sequence issue wouldn't matter in log4j 
> (sqlDialect.getSelectInsertId()).
>         The only mandatory option would be "TableName".
>         All other options would be interpreted as column names with the 
> value of the option being passed through the layout class. Example:
>
>   <param name="TableName" value="logging_event" />
>   <param name="message" value="%m" />
>   <param name="catagory" value="%c" />
>   <param name="Thread" value="%t" />
>   <param name="machine" value="machine" /><!-- different machines would 
> have different values here in their log4j.xml -->
>
>   <param name="Priority" value="%p" />
>   <param name="Time" value="%d" />
>   <param name="Short_Message" value="%p @ %d: %m" />
>   <param name="URL" value="%X{url}" />
>   <param name="stack" value="%throwable" />
>
>   Con: Lots more coding.
>         More complex.
>         Stack traces can be long so how would that be handled so that 
> overflow wouldn't prevent logging.
>         Are arbitrary options supported?
>         Would everyting have to go in the Database as a string?
>         How would dates and sequence numbers be handled?
>         Could we treat the value as a date if(value.startsWith(%d) || 
> (value.startsWith(%d{) && value.indexOf("}") == value.length()))?
>
>Comments?
>
>James Stauffer
>

-- 
Ceki Gülcü

      For log4j documentation consider "The complete log4j manual"
      ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp  



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org