Hibernate - how to i initialize the log4j system properly

We have finally decided to use Hibernate + Spring to build our large core system so I start learning and using it. I'm using Eclipse 3.1 and plug-in Hibernate. The following is my java code to use session factory.

try {            
   sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
   throw new ExceptionInInitializerError(ex);
}

When I run the java program I got the following warning message:

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

Any idea how to i initialise the log4j system proplerly and create the log

Many thanks in advance

LeanMoreTryMoreAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
put a log4j config file in the classpath
Mick BarryJava DeveloperCommented:
LeanMoreTryMoreAuthor Commented:
Thanks.

I have created a log4j.xml file.
Both log4j.xml and hibernate.cfg.xml reside in the same folder


log4j.xml file
--------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    <appender name="myAppender"
              class="org.apache.log4j.FileAppender">
       <layout class="org.apache.log4j.SimpleLayout"/>
    </appender>
    <root>
        <priority value="debug" />
        <appender-ref ref="myAppender"/>
    </root>
</log4j:configuration>


================================================================

And i import log4j to the start-up class like below

import org.apache.log4j.PropertyConfigurator;

But i got the following warning messages

log4j:WARN File option not set for appender [myAppender].
log4j:WARN Are you using FileAppender instead of ConsoleAppender?
log4j:ERROR No output stream or file set for the appender named [myAppender].
Mick BarryJava DeveloperCommented:
add the file that you want to log to:

    <appender name="myAppender" class="org.apache.log4j.FileAppender">
       <param name="File" value="my.log"/>
       <layout class="org.apache.log4j.SimpleLayout"/>
    </appender>


(Not sure why that article left it out)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LeanMoreTryMoreAuthor Commented:
Thanks. it works.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.