• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java application cannot found the log4j.properties

 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The application is a very simple maven application, I put the log4j.properties in resources folder, then I run mvn clean package, then in ecllipse, I right click the project and choose run as java application, but error


No appenders could be found for logger (x.y.TestLog4j)
Please initialize the log4j system properly.



I think the application cannot load the log4j.properties, but how to let the application find the log4.properties?
I check api and there is some
PropertyConfigurator.configure(URL);
but I do not know how to create the URL. any help is appreciated.

the log4j.properties is as follow:


x=ERROR, A1, A2
log4j.appender.A1=org.apache.log4j.ConsoleAppender


log4j.appender.A1.layout=org.apache.log4j.PatternLayout


log4j.appender.A1.layout.ConversionPattern=%d %-5p (%13F:%L) %3x - %m%n

# Appender A2 writes to the file "test".
log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A2.DatePattern='.'yyyy-MM-dd
log4j.appender.A2.File=./debugleveldemo_logs/debugleveldemo.log


# Appender A2 uses the PatternLayout.
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n

Log4j.jpg
[Thumbnail for Log4j.jpg]
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When maven builds the project and you run the target app, the log4j properties file must be in the runtime CLASSPATH at its root. For webapps, that mean in the WEB-INF/classes directory.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic