V
vaneric
hello guys,
I am trying to use log4j Logger in my web application.I decided to use
it in my servlet as given below.
import org.apache.log4j.Logger;
public class ReqViewerServlet extends HttpServlet {
private Logger log;
public ReqViewerServlet()
{ java.util.ResourceBundlebundle=java.util.ResourceBundle.getBundle
("include");
String logfile=bundle.getString("logfilename");
log=Logger.getLogger(logfile);
}
....
}
where I created an include.properties file containing
------------
logfilename=myapplog
and in log4j.properties ,
-----------
log4j.logger.myapplog=DEBUG,myLogfile
log4j.appender.myLogfile.File=mywebapp.log
--------------------
As expected this causes the log.debug(..) statements in the servlet
code to be written to mywebapplog.log
What bothers me is that ,I have a servlet constructor solely for
creating the Logger instance.It doesn't feel right.Is there a better
way to initialize the Logger instance in my code?
thanks in advance
eric
I am trying to use log4j Logger in my web application.I decided to use
it in my servlet as given below.
import org.apache.log4j.Logger;
public class ReqViewerServlet extends HttpServlet {
private Logger log;
public ReqViewerServlet()
{ java.util.ResourceBundlebundle=java.util.ResourceBundle.getBundle
("include");
String logfile=bundle.getString("logfilename");
log=Logger.getLogger(logfile);
}
....
}
where I created an include.properties file containing
------------
logfilename=myapplog
and in log4j.properties ,
-----------
log4j.logger.myapplog=DEBUG,myLogfile
log4j.appender.myLogfile.File=mywebapp.log
--------------------
As expected this causes the log.debug(..) statements in the servlet
code to be written to mywebapplog.log
What bothers me is that ,I have a servlet constructor solely for
creating the Logger instance.It doesn't feel right.Is there a better
way to initialize the Logger instance in my code?
thanks in advance
eric