Hi,

I  am trying to insert the logs in database.

It works fine.When i want to pass some variables to the log file for inserting
it doesnt work.

For eg

import org.apache.log4j.Logger;
import org.apache.log4j.MDC;

import com.test.constants.LogConstants;


/**
 * @author admin
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Play {

        public static Logger logger =  Logger.getLogger(LogConstants.LOGGER_DB);
        
        public static void main(String[] args) {
                System.out.println("START PLAY");
                
                MDC.put("User", "128.23.25.23");
                
                logger.debug("throws Exception to define... ");
                                
                System.out.println("END PLAY");
        }
}


The above code puts ip address.

I am trying to access the "User" key in sql statement as below

log4j.appender.database.sql=INSERT INTO TAB_MESSAGE_LOG (log_id,log_desc,
creation_date) VALUES (seq_message_log.NextVal,'@User@',SYSDATE)

It doesn't work, what am i doing wrong here.

It works fine if i insert in log file, in the below way,
log4j.appender.service.layout.ConversionPattern=%p - [%X{User}] - %m%n


What i am doing wrong in this case
log4j.appender.database.sql=INSERT INTO TAB_MESSAGE_LOG (log_id,log_desc,
creation_date) VALUES (seq_message_log.NextVal,'@User@',SYSDATE)

Appreciate your help



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

Reply via email to