Virat Lohith
Virat Lohith

Reputation: 35

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment)

When I develop a sample app on hibernate which is inserting pojo class object into database using hibernate framework.. I got error message like

"WARN No appenders could be found for logger (org.hibernate.cfg.Environment).".

I don't know what it means...I also add hibernate configuration xml file and also add mapping file..i'm using web logic server. This is my project architecture

Upvotes: 0

Views: 3986

Answers (1)

VladoDemcak
VladoDemcak

Reputation: 5259

I see that in your project architecture there is log4j library that needs to set some appenders and basically some properties to get it works properly.

You are using log4j.1.2.15 so Log4j documentation says:

Log4j allows logging requests to print to multiple destinations. In log4j speak, an output destination is called an appender. Currently, appenders exist for the console, files, GUI components, remote socket servers, JMS, NT Event Loggers, and remote UNIX Syslog daemons.

So basically log4j is not aware of any output destination and you need to tell to log4j explicitly where it should log all messages - You tell him this information in log4j.properties with properties and configuration for appender.

I think you can add log4j.properties next to hibernate.cfg.xml with following configruation and the WARN message should disappear. This is the simple configuration for log4j.properties:

# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, A1

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

Upvotes: 3

Related Questions