-->
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.  [ 7 posts ] 
Author Message
 Post subject: Log4j xml
PostPosted: Tue Feb 19, 2008 12:11 pm 
Newbie

Joined: Tue Feb 19, 2008 12:08 pm
Posts: 3
Are there any examples on how to config log4j xml file for logging. have seen examples using properties file.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 19, 2008 12:33 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
probably in the log4j documentation

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 19, 2008 12:36 pm 
Newbie

Joined: Tue Feb 19, 2008 6:48 am
Posts: 17
Use this example:

Code:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
       
  <appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.SimpleLayout"/>
  </appender>

  <root>
    <priority value ="debug" />
    <appender-ref ref="ConsoleAppender"/>
  </root>

</log4j:configuration>


For more information, use log4j documentation or see the folowing wiki http://wiki.apache.org/logging-log4j/Log4jXmlFormat

_________________
João Simas


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 19, 2008 12:45 pm 
Newbie

Joined: Tue Feb 19, 2008 12:08 pm
Posts: 3
Perhaps more clarity needed. I'm getting the following:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.

I have not seen any examples in xml form in the documentation or the "Java Persistence with Hibernate" book.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 19, 2008 1:21 pm 
Newbie

Joined: Tue Feb 19, 2008 6:48 am
Posts: 17
You have no initialize log4j.

In web.xml add:

Code:
   <context-param>
      <param-name>log4jConfigLocation</param-name>
      <param-value>/WEB-INF/classes/conf/log4j.xml</param-value>
   </context-param>


you may have to change the value /WEB-INF/classes/conf/log4j.xml.

and then add:

Code:
   <listener>
      <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
   </listener>


And the log4j should be initialized correctly.

_________________
João Simas


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 19, 2008 3:18 pm 
Newbie

Joined: Tue Feb 19, 2008 12:08 pm
Posts: 3
I have to introduce spring listener into the equation. I'd think there would eb another way.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 20, 2008 6:42 am 
Newbie

Joined: Tue Feb 19, 2008 6:48 am
Posts: 17
The other way is to build a listener that initiliaze Log4j:


Code:
public class Log4jInitializer implements ServletContextListener {

   public void contextInitialized(ServletContextEvent arg0) {
      PropertyConfigurator.configure("log4j.xml");
   }
   
   public void contextDestroyed(ServletContextEvent arg0) {
   }

}

_________________
João Simas


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.