-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 posts ] 
Author Message
 Post subject: Turning on logging, doesn't work for me...
PostPosted: Wed Oct 01, 2003 9:56 am 
Beginner
Beginner

Joined: Sat Sep 20, 2003 4:23 am
Posts: 48
And another newbie question. I want to log my hibernate messages to a file or to the Mac OSX console.

I have my log4j.jar in my classpath as well as my hibernate.properties:

Code:
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### direct messages to file hibernate.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=hibernate.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ##

log4j.rootLogger=debug, stdout

log4j.logger.net.sf.hibernate=debug

### enable the following line if you want to track down connection ###
### leakages when using DriverManagerConnectionProvider ###
#log4j.logger.net.sf.hibernate.connection.DriverManagerConnectionProvider=trace

### log JDBC bind parameters ###
log4j.logger.net.sf.hibernate.type=debug

### log prepared statement cache activity ###
log4j.logger.net.sf.hibernate.ps.PreparedStatementCache=debug


however, I cannot find my logfile 'hibernate.log' and my console doesn't spit the logs out either.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 10:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Turn on log4j debugging. Is it actually finding and using this file?

This should send logging to the console. You never add the appender named "file" to any of the loggers, so there would not be a file.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 11:21 am 
Beginner
Beginner

Joined: Sat Sep 20, 2003 4:23 am
Posts: 48
Probably a stupid question, but how to turn on logging with a servlet? Obviously a '-Dlog4j.debug=true' isn't appropiate here...

log4j.properties is in WEB-INF/classes btw, also tried to put it in WEB-INF/lib with no luck.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 12:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Is this on a servlet container that also uses log4j (like tomcat, etc) for its own logging?

Quote:
Obviously a '-Dlog4j.debug=true' isn't appropiate here

Why? If you or your organization owns the box (meaning its not an ISP or ASP), thats a perfectly valid option. There is actually no other way to turn on log4j debugging such that the file being used for config is debugged out. You can set the debug attribute of the XML-based config, but by that time the config file has been read and the path to it is never logged.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 12:50 pm 
Beginner
Beginner

Joined: Sat Sep 20, 2003 4:23 am
Posts: 48
steve wrote:
Is this on a servlet container that also uses log4j (like tomcat, etc) for its own logging?


It's on Tomcat

Quote:
Why? If you or your organization owns the box (meaning its not an ISP or ASP), thats a perfectly valid option. There is actually no other way to turn on log4j debugging such that the file being used for config is debugged out. You can set the debug attribute of the XML-based config, but by that time the config file has been read and the path to it is never logged.


Ok, frankly don't know how exactly, but will try to find out


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 1:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
1) place your log4j.jar file in WEB-INF/lib
2) place your config file in WEB-INF/classes


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 2:17 pm 
Beginner
Beginner

Joined: Sat Sep 20, 2003 4:23 am
Posts: 48
steve wrote:
1) place your log4j.jar file in WEB-INF/lib
2) place your config file in WEB-INF/classes


That's how the situation was in the first place :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 2:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
I don't use tomcat, so I am just passing along information from the log4j mailing list.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 03, 2003 6:02 pm 
Beginner
Beginner

Joined: Sat Sep 20, 2003 4:23 am
Posts: 48
Ok, I've set debug=true and it's debugging to a log4j.log file now. However I cannot find any information regarding loading a log4j.properties file for my project, so it seems that it's not using log4j... But why?

I've put the properties-file in my WEB-INF/classes and the library in WEB-INF/lib, so that should be it right?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 03, 2003 9:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
It all depends. Hibernate actually uses commons logging, which can delegate to either log4j or 1.4 logging.

As I mentioned in my first response to you, that config that you posted would never generate a hibernate.log file. You define the appender, but then never attach it to any loggers.

Have you checked in the tomcat logs? I think I remember reading that tomcat actually redirects the console to its log files.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 04, 2003 5:39 am 
Beginner
Beginner

Joined: Sat Sep 20, 2003 4:23 am
Posts: 48
I changed my config file since you mentioned it, but still no luck :(

I checked the tomcat logs and nothing I could find...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 04, 2003 9:49 am 
Beginner
Beginner

Joined: Sat Sep 20, 2003 4:23 am
Posts: 48
Ok, found a possibly related error in catalina.out:

Code:
com.opensymphony.user.util.ConfigLoader load
SEVERE: Exception
java.lang.NoClassDefFoundError: net/sf/hibernate/HibernateException
   at com.opensymphony.user.provider.hibernate.HibernateBaseProvider.init(HibernateBaseProvider.java:80)
   at com.opensymphony.user.util.ConfigLoader.addProvider(ConfigLoader.java:123)
   at com.opensymphony.user.util.ConfigLoader.access$100(ConfigLoader.java:37)
   at com.opensymphony.user.util.ConfigLoader$ConfigHandler.endElement(ConfigLoader.java:154)
   at
...


this is the error that the servlet throws up:

Code:
java.lang.RuntimeException: net/sf/hibernate/HibernateException
        com.opensymphony.user.util.ConfigLoader.load(ConfigLoader.java:74)
        com.opensymphony.user.UserManager.(UserManager.java:103)
        com.opensymphony.user.UserManager.(UserManager.java:58)
        org.mathesis.test.OSUserTest.doGet(OSUserTest.java:35)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:853)


I've got hibernate.jar in my WEB-INF/lib directory...

This is the servlet code:

Code:
/*
* Created on 29-sep-2003
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package org.mathesis.test;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Iterator;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.opensymphony.user.DuplicateEntityException;
import com.opensymphony.user.ImmutableException;
import com.opensymphony.user.User;
import com.opensymphony.user.UserManager;
import com.opensymphony.user.provider.CredentialsProvider;

/**
* @author iljahehenkamp
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class OSUserTest extends HttpServlet
{
   public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
   {
      UserManager um = new UserManager();
      PrintWriter out = response.getWriter();
      
      Collection credentialProviders = null;
      
      try
      {
         credentialProviders = um.getCredentialsProviders();
         
         for (Iterator iterator = credentialProviders.iterator(); iterator.hasNext();)
         {
            CredentialsProvider provider = (CredentialsProvider) iterator.next();
         }
      }
      catch (NullPointerException e)
      {
         // TODO Auto-generated catch block
         e.printStackTrace(out);
      }
      
      try
      {
         User u = um.createUser("jan wandelaar");
      }
      catch (DuplicateEntityException e)
      {
         // TODO Auto-generated catch block
         e.printStackTrace(out);
      }
      catch (ImmutableException e)
      {
         // TODO Auto-generated catch block
         e.printStackTrace(out);
      }
      catch (NullPointerException e)
      {
         // TODO Auto-generated catch block
         e.printStackTrace(out);
      }
      catch (RuntimeException e)
      {
         // TODO Auto-generated catch block
         e.printStackTrace(out);
      }
      catch (Exception e)
      {   
         e.printStackTrace(out);
      }
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 04, 2003 1:32 pm 
Beginner
Beginner

Joined: Sat Sep 20, 2003 4:23 am
Posts: 48
woops, wrong thread (although somewhat related...)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.