• 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

Log4j RollingFileAppender doesn't write to file in Websphere

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello:
I'm trying to use Log4j in my servlets but it won't write to a file even though I did not get any error messages.
I'm using a servlet (in Websphere) to init the Log4j properties and the servelt is set to "Load on startup". Here is the servlet:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.log4j.PropertyConfigurator;
public class Log4jInit extends HttpServlet {
public void init() throws ServletException {
PropertyConfigurator.configure("log4j.properties");
}
}
-----
This is my log4.properties file:
# Set root category priority to ERROR and its only appender to A1.
log4j.rootCategory=error, R
# R is set to be a RollingFileAppender.
log4j.appender.R=org.apache.log4j.RollingFileAppender
# set up the filename - change as appropriate
log4j.appender.R.File=error.log
# R uses PatternLayout.
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
---
This is my test servlet:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
import org.apache.log4j.*;
public class OASQAdminServlet extends HttpServlet {
static Category mLog = Category.getInstance(AdminServlet.class.getName());
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
response.setContentType("text/html");
mLog.error("*** in doPost ***");
out.println("hello");
out.close();
}
}
Any help will be greatly appreciated.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check which version of JDK you have on this machine.
Log4J doesn't work with JDK less than 1.2, I've got the very same problem under OS/390 + WebSphere.
Hope it'll help.
Alex.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alex:
Websphere has its own jdk and it's 1.2, and I'm using jdk1.3.1 also.
Thanh
[ January 22, 2002: Message edited by: downasn ]
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"downasn"
We require that all posters comply with the Official JavaRanch Naming Policy. Please take a few moments to review it and then re-register under a name that conforms with the policy. Remember, your Displayed Name must conform to the naming policy.
Thanks for your cooperation and welcome to JavaRanch!
Junilu Lacar
Jakarta Projects Forum Moderator
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I think the order of methd callsS is wrong.
It has to be
First, PropertyConfigurator.configure() and then
Category.getInstance().
So do both of these inside the class definition or move both inside init() method of servlet.
LOG4J doesn't throw any exceptions. What they do is catch the exceptions and send the error message to System.err or System.out.
If u check your Web/Application servers's log file u will see a log saying "configuration file not found for category ..." or something to that effect.
The LOG4J error logs start with the string "LOG4:".
So u can easiy filter out your log file and find the cause of the error and fix it.
Hope this helps.
Good luck.
Vignes Inpanathan
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vignes:
Thank you for trying to help me. I checked the server log file and couldn't find any error messages pertaining to Log4j. I also switched the order of the calls around like you suggested but it still doesn't write to a file.
Thanh
[ January 26, 2002: Message edited by: Thanh Nguyen ]
 
Vignes_Inpanathan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The location of the properties file could be an issue.This is a suggestion.
Where do u have the log4j.properties file?
Since u have used a relative path, the file should be in the same folder as the servlet.
Or else if u want to keep the properties file in a separate folder, then u have to give the absolute path to the
PropertyConfigurator.configure() method call.
Try this out. U can always write to LOG4J team for help.
But u have to be very specific about your settings.
Good luck.
Inpanathan
 
It's a tiny ad. At least, that's what she said.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic