[jboss-dev-forums] [Deployers on JBoss (Deployers/JBoss)] - Problems with log4j in jboss

dadevilzadvocate do-not-reply at jboss.com
Wed Jul 18 01:21:26 EDT 2007


Please i need help because i can't anywhere else.
Below is the log4j properties file
# initialise root logger with level INFO and call it 
log4j.rootLogger=INFO, BLAH
# add a Appender to the logger BLAH
log4j.appender.BLAH=org.apache.log4j.RollingFileAppender
# set the layout
log4j.appender.BLAH.layout=org.apache.log4j.PatternLayout
#log4j.appender.BLAH.layout.ConversionPattern=%p %c - %m%n
log4j.appender.BLAH.layout.ConversionPattern=%d{dd-MMM-yyyy HH:mm:ss:SSS}: %m%n

log4j.appender.BLAH.File=c:/testing.log

log4j.appender.BLAH.MaxFileSize=10000KB
# Keep one backup file
log4j.appender.BLAH.MaxBackupIndex=10

Below is the code in which i am using log4j logging
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.PrintWriter;
import java.io.IOException;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

public class rectest extends HttpServlet 
{
private static final String CONTENT_TYPE = "text/html; charset=windows-1252";

public void init(ServletConfig config) throws ServletException
{
super.init(config);
String prefix = "D:/jdkwork/work/App/testing";
String file = getInitParameter("log4j-init-file");
// if the log4j-init-file is not set, then no point in trying
if(file != null) {
PropertyConfigurator.configure(prefix+file);
}
}
private static Logger log =Logger.getLogger(rectest.class);
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doPost(request,response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("");
out.println("rectest");
out.println("");
log.info("this is a test");
out.println("The servlet has received a POST. This is the reply.");
out.println("");
out.close();
}
}
I deploy the war file in jboss4.0.5 and run it. It runs smoothly and when deploys the war file, all the info messages in the console are then logged to the log file of my application which is deployed in it. i am new to log4j and couldn't find solution for that. please help 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4065248#4065248

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4065248



More information about the jboss-dev-forums mailing list