File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes Log4j RollingFileAppender doesn't write to file in Websphere Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Log4j RollingFileAppender doesn Watch "Log4j RollingFileAppender doesn New topic
Author

Log4j RollingFileAppender doesn't write to file in Websphere

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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.
Alex Givant
Greenhorn

Joined: Nov 12, 2001
Posts: 23
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

Joined: Nov 22, 2008
Posts: 18944
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 ]
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4442
    
    5

"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
Vignes_Inpanathan
Greenhorn

Joined: Jan 23, 2002
Posts: 3
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

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Jan 23, 2002
Posts: 3
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Log4j RollingFileAppender doesn't write to file in Websphere
 
Similar Threads
RequestDispatcher problem
servlet package not found
get a servlet name
HttpServletResponse obj lost after using System.getProperty
Problem compiling servlet [RESOLVED]