You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by jo...@canopyint.com on 2003/02/26 21:38:09 UTC

JDBCAppender - passing parameters to SQL statement

Hi,

I would like to know how to pass parameters into a SQL statement defined in
a JDBCAppender.

Suppose I have a table such as:

create table logtest (
     logDate date,
     prio varchar(15),
     cat varchar(30),
     msg varchar(255),
     extraInfo varchar(255));
                                                                            
                                                                            
 I want the extraInfo column populated every time I log a message.          
 (1) How do I define the SQL statement in the log4j.properties file to      
 accept parameters?                                                         
                                                                            
 log4j.appender.R=org.apache.log4j.jdbc.JDBCAppender                        
 log4j.appender.R.URL=jdbc:mysql://localhost/LOG4JDemo                      
 log4j.appender.R.user=default                                              
 log4j.appender.R.password=default                                          
 log4j.appender.R.sql=INSERT INTO JDBCTEST (Message) VALUES ('%d - %p - %c  
 - %m')                                                                     
                                                                            


In code,  after we get a log4j logger instance,
(2) how do I pass this extra information to the logger so that it can use
it in the SQL statement?

logger.WARN("Warning Message"); // I want to pass more info than just the
"Warning Message"

Thanks in advance.

John




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