Announcement Announcement Module
Collapse
No announcement yet.
Spring Logs and Toplink Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Logs and Toplink

    Hi,

    I use spring, with toplink and log4j on tomcat.

    I have a configuration which allows me to log the output to a file for my program and as desired the output of Spring Framework. Unfortunately the output for toplink only goes to the console and not in my file.

    What I see in the console is the log4j formatted output, and we see the toplink output, but as seen in the following snipped we can guess that toplink's output is not sent to the console by log4j.

    Code:
    11:38:47,720 DEBUG AjaxController [jtremblay(008)127.0.0.1] Binding request parameters onto MultiActionController command
    [TopLink Fine]: 2010.04.15 11:38:47.732--Connection(1897566795)--SELECT ID, OBJECT_TYPE, MODIFICATIONDATE, CREATIONDATE, MODIFICATIONPERSON_ID, CREATIONPERSON_ID, CONTRACT_ID, HSCODE, CO_NUM FROM cust_contract_extra_object WHERE ((CONTRACT_ID = ?) AND (OBJECT_TYPE = ?)) ORDER BY HSCODE ASC
    	bind => [14, FREE_PRICE_ELEMENTS]
    11:38:47,733 INFO  LogRequestInterceptor [jtremblay(008)127.0.0.1] <<< REQUEST COMPLETED(008) elapsed: 00.015 sec.
    11:39:41,064 INFO  ShowSystemStatus [()] 92.1 MB/490.69 MB (18% used)
    11:40:41,064 INFO  ShowSystemStatus [()] 99.17 MB/490.69 MB (20% used)
    11:41:41,065 INFO  ShowSystemStatus [()] 106.24 MB/490.69 MB (21% used)
    I have found out that if I extended the preLogin method from the class oracle.toplink.essentials.sessions.SessionEventAda pter I could solve my problem. My problem now is that I have no clue how to hook this class.

    Does anyone out there have any idea how I could inject this in my application?

  • #2
    SessionCustomizer a better fit.

    The easiest is to use the same code from the SessionEventAdaptor but put it in a SessionCustomizer. TopLink can be configured to use a session customizer through the persistence unit property "toplink.session.customizer" see http://www.oracle.com/technology/pro...tionValidation for details.

    Comment


    • #3
      Thanks Gordon. You're the man!
      That is exactly what I was looking for.

      For those interested this is how I have done it:
      I created a SessionCustomizer
      Code:
      public class MySessionCustomizer implements SessionCustomizer{
      	SessionLog sessionLog = new MyToplinkSessionLog();
      
      	@Override
      	public void customize(Session session) throws Exception {
      		session.setSessionLog(sessionLog);
      	}
      }
      I create a SessionLog:
      Code:
      public class MyToplinkSessionLog extends AbstractSessionLog{
      	private static final Logger	log = LoggerFactory.getLogger(MyToplinkSessionLog.class);
      	private static final long serialVersionUID = -7420299497749865740L;
      	
      	@Override
      	public synchronized void log(SessionLogEntry sessionLogEntry) {
              String message = formatMessage(sessionLogEntry);
              int level = sessionLogEntry.getLevel();
              if(level < FINE)
              	return;
              else if(level <= WARNING)
              	log.info(message);		
              else if(sessionLogEntry.hasException())
              	log.error(message, sessionLogEntry.getException());
              else
              	log.error(message);
      	}
      }
      Now all that was needed is Gordon's great hint.
      Add this one line to the persistence.xml
      Code:
      <property name="toplink.session.customizer" value="com.zen.toplink.MySessionCustomizer"/>

      Comment

      Working...
      X