• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

log4j:ERROR Could not read configuration file

 
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm getting error when setting up log4j and I don't know how to resolve.
log4j:

ContextListener:

Use:

Log:

Thanks in advance by any help.
 
Sheriff
Posts: 22650
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cezar Apulchro wrote:


You don't have an init parameter called log4j.properties. The value for the log4jConfigFile is null, which can clearly be seen in the error.
 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I I changed to:

and now the log is generated but the error still the same.
Report:

 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my log4j.properties:
image.jpg
[Thumbnail for image.jpg]
 
Saloon Keeper
Posts: 13889
314
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is likely that you added a path separator to a path that already ended with a path separator.

The solution is NOT to remove the path separator. Messing with file paths in a web application is asking for trouble.

The properties file should be at the root of your classpath. If so, I believe you don't have to write a context listener to configure log4j, log4j will automatically pick it up.

Put your configuration file in src/main/resources and Maven will copy it to the correct location.
 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
New error:
 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this error is after the change that you told me to do.
 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and the log file is not generated.
 
Master Rancher
Posts: 4197
57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error message contains the complete path of the file it is looking for, and not finding.  Study that - does that path exist on your machine?  Does part of it exist, at least?  Which parts exist, and which do not?  Looking carefully there will help you see where the problem is.
 
Rob Spoor
Sheriff
Posts: 22650
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's the same error. context.getInitParameter returns the value of an init-parameter that has the given name.

Try getting rid of the call to context.getInitParameter completely.
 
Saloon Keeper
Posts: 25477
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:It's the same error. context.getInitParameter returns the value of an init-parameter that has the given name.

Try getting rid of the call to context.getInitParameter completely.



Don't use File.separator in URLs or in Java resource paths. They're based on Unix-style paths and never on Windows paths, so the proper separator is always "/", even in Windows. Resource paths should also always be absolute. That is, "/WEB-INF/classes/log4j.properties" and not "WEB-INF/classes/log4j.properties". Using relative resource paths can lead to unfortunate surprises.
 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After change made:

The result is:

Report log generated:
 
Tim Holloway
Saloon Keeper
Posts: 25477
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Additional note:

Spring Boot produces an executable JAR. If you use getRealPath() to find a "file" within a JAR (or unexploded WAR) it will return null, because there is no "real" path inside a JAR, only a resource path.

It' VERY important to realize that resources often are not files and therefore should not be read via filesystem operations.
 
Cezar Apulchro
Ranch Hand
Posts: 453
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't be using Spring Boot.
 
Tim Holloway
Saloon Keeper
Posts: 25477
180
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

Cezar Apulchro wrote:I don't be using Spring Boot.

It doesn't matter.

ANY webapp that's inside a JAR/WAR/EAR file will see the same problem for the same reason. However you were playing around with Spring Boot at one time, I believe and since Spring Boot apps are always JARs, I mentioned it specifically.
 
"How many licks ..." - I think all of this dog's research starts with these words. Tasty tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic