Posted By:
Anonymous
Posted On:
Wednesday, June 25, 2003 03:50 AM
You can use Log4j within Struts as you would use it within every other java class.
First make sure Log4j.jar is in you're classpath and within you're java class for example a Struts Action class you type:
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.log4j.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MyAction extends Action {
public static final String FORWARD_SUCCESS = "success";
private static final Logger log = Logger.getLogger(MyAction.class);
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
log.error("This error message shouldn't be here");
// a check if the logger is debug enabled only placed this check here for performance issues
if (log.isDebugEnabled) {
log.debug("A debug message in my MyAction class");
}
return actionMapping.findForward(FORWARD_SUCCESS);
}
If you want to know more about log4j (configuration of log4j , etc) read the following manual.
http://jakarta.apache.org/log4j/docs/manual.html