[prev in list] [next in list] [prev in thread] [next in thread] 

List:       log4j-user
Subject:    RE: JDBCAppender - passing parameters to SQL statement
From:       john.fairbairn () canopyint ! com
Date:       2003-02-27 13:13:12
[Download RAW message or body]


Thanks for this Michael. Just what I needed.

Regards,

John



                                                                                      \
                
                    Lutz Michael                                                      \
                
                    <michael.h.lutz@si       To:     "'Log4J Users List'" \
                <log4j-user@jakarta.apache.org>              
                    emens.com>               cc:                                      \
                
                                             Subject:     RE: JDBCAppender - passing \
                parameters to SQL statement       
                    02/26/2003 04:51                                                  \
                
                    PM                                                                \
                
                    Please respond to                                                 \
                
                    "Log4J Users List"                                                \
                
                                                                                      \
                
                                                                                      \







Wooops, 1 minor correction.
"Lgg" shouldn't be on the front of PatternLayout in the config file.
Sorry about that.


-----Original Message-----
From: Lutz Michael
Sent: Wednesday, February 26, 2003 4:40 PM
To: 'Log4J Users List'
Subject: RE: JDBCAppender - passing parameters to SQL statement



Here's an example, working config file that includes usage of the JDBC
Appender similarly to your example.

# **********************************************
log4j.rootLogger=DEBUG, myJDBC
log4j.appender.myJDBC=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.myJDBC.URL=jdbc:microsoft:sqlserver://<server_here>;DatabaseN

ame=<database_here>
log4j.appender.myJDBC.User=<userid_here>
log4j.appender.myJDBC.Password=<password_here>
log4j.appender.myJDBC.Driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
#
log4j.appender.myJDBC.layout=com.siemens.med.hs.commoncomponents.logging.Lgg

PatternLayout
log4j.appender.myJDBC.layout=org.apache.log4j.PatternLayout
log4j.appender.myJDBC.layout.ConversionPattern=INSERT INTO LogRepository
VALUES ('%p', '%d{MM/dd/yyyy HH:mm:ss.SSS}', '%m', '%F', '%L', '%t', '%c',
'%X{hostname}', '%X{hostaddress}', '%X{userid}', '%X{gsmsessionid}',
'%X{processtype}', '%X{transid}', '%X{entcode}', '%X{hospcode}',
'%X{environment}', '%X{reserved1}', '%X{reserved2}', '%X{reserved3}',
'%X{reserved4}', '%X{reserved5}', '%X{reservedint1}', '%X{reservedint2}',
'%X{reservedint3}', '%X{reservedint4}', '%X{reservedint5}')
# **********************************************

To achieve passing additional information to log4j, you've got two options.
Option 1 is to use MDC, which most people seem to prefer.  MDC requires
separate calls before the actual logging call to set the MDC value.  MDC is
simply key/value pairs stored per thread of execution.  (see the MDC
JavaDoc)

The second option is to pass an object into Log4j instead of a String, and
extend PatternParser and PatternLayout to understand the new conversion
characters.  For an example, see
http://www.ingrid.org/jajakarta/log4j/jakarta-log4j-1.1.3/docs/deepExtension

.html.




-----Original Message-----
From: john.fairbairn@canopyint.com [mailto:john.fairbairn@canopyint.com]
Sent: Wednesday, February 26, 2003 3:38 PM
To: log4j-user@jakarta.apache.org
Subject: 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

-------------------------------------------------------------------------------

This message and any included attachments are from Siemens Medical
Solutions
Health Services Corporation and are intended only for the addressee(s).
The information contained herein may include trade secrets or privileged or

otherwise confidential information.  Unauthorized review, forwarding,
printing,
copying, distributing, or using such information is strictly prohibited and
may
be unlawful.  If you received this message in error, or have reason to
believe
you are not authorized to receive it, please promptly delete this message
and
notify the sender by e-mail with a copy to CSOffice@smed.com.  Thank you

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






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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic