Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

log4j:ERROR Ignoring configuration file [WEB-INF/log4j.properties

 
Greenhorn
Posts: 24
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please sort out this problem
System.log file is not generated



private void processRequest(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException {

//BasicConfigurator.configure();// Its running properly
PropertyConfigurator.configure("WEB-INF/log4j.properties");// when using this it's showing error
response.setContentType("text/html;charset=UTF-8");
PrintWriter out=response.getWriter();
try{
logger.info("Invoked the logging servlet");
out.println("Check your web server console");
out.flush();
out.close();
}
finally{
out.close();
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}


//log4j.properties
----------------------------------
log4j.rootLogger=debug, stdout
log4j.appender.stdout=org.apache.log4j.FileAppender
log4j.appender.stdout.File=system.log
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%5p] %d{mm:ss} (%F:%M:%L)%n%m%n%n



console output:-
---------------------------------------


Jun 1, 2011 10:22:53 AM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Sun's JavaServer Faces implementation (1.2_03-20070706-NIGHTLY) for context '/servletwithlog4j'
Jun 1, 2011 10:22:54 AM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Sun's JavaServer Faces implementation (1.2_03-20070706-NIGHTLY) for context '/servletwithlog4j'
log4j:ERROR Could not read configuration file [WEB-INF/log4j.properties].
java.io.FileNotFoundException: WEB-INF\log4j.properties (The system cannot find the path specified)

at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:316)
at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:342)
at logservlet.LoggingServlet.processRequest(LoggingServlet.java:28)
at logservlet.LoggingServlet.doGet(LoggingServlet.java:42)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3496)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)

log4j:ERROR Ignoring configuration file [WEB-INF/log4j.properties].
log4j:WARN No appenders could be found for logger (logservlet.LoggingServlet).
log4j:WARN Please initialize the log4j system properly.
 
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Keep this file in "WEB-INF/classes" and then load it using getResourceAsStream() which will locate the file in the CLASSPATH configured for your application.
I mentioned "WEB-INF/classes" as this is already included in the classpath when webapp starts and loads the classes.

Regards,
Amit
 
vivek kumar jaiswal
Greenhorn
Posts: 24
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi amit,
I have add it but problem is different:

String name=null;
InputStream is = getClass().getResourceAsStream("log4j.properties");
Properties p = new Properties();
try {
p.load(is);

name= p.getProperty("log4j.properties");
} catch (IOException e) {
System.out.println("error loading props...");
}

console error:

log4j:ERROR Ignoring configuration file [null].
means NullPointerException
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

What is this line of code doing?


name= p.getProperty("log4j.properties");



Regards,
Amit
 
vivek kumar jaiswal
Greenhorn
Posts: 24
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amit,

This code is return the value of the key that is set in properties. That code is wrong. I have check please give me the proper guideline how to solve this problem that is mention above.

regards,

VIVEK
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Can you tell me
1) If the FileNotFoundException as mentioned in your first post is gone ??
2) You are loading the "log4j.properties" using InputStream into Properties object but you still need to initialize the Log4j by calling
PropertyConfigurator.configure(p). Are you facing error even after doing this?

Regards,
amit
 
vivek kumar jaiswal
Greenhorn
Posts: 24
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amit,

Thanks It is running properly.
Where are you from? and give me your contact no or email id.

InputStream is = getClass().getResourceAsStream("log4j.properties");
Properties p = new Properties();
p.load(is);
PropertyConfigurator.configure(p);

regards,
VIVEK
 
She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic