Java程序默认输出为Console,如果要想将Console输出结果保存到文件中,则需要做如下配置:
在JAVA程序上右键--> Run As --> Run Configurations
选择Common窗口,设置文件保存路径,以及是否以追加方式保存console输出到文件。
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
Log log=LogFactory.getLog("--start--");
log.fatal("this id a fatal message");
log.error("this id a error message");
log.warn("this id a warn message");
log.info("this id a info message");
if(log.isDebugEnabled()){
log.debug("this id a debug message");
}
LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
String name=loginForm.getName();
String password=loginForm.getPassword();
if(name.equals("abc")&&password.equals("111")){
return mapping.findForward("go");
}else{
return mapping.findForward("go1");
}
}
log4j.rootLogger=INFO,console,file
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=d:/Log/log.html
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%r%t%p-%m%n
log4j.appender.file.layout=org.apache.log4j.HTMLLayout
Atas ialah kandungan terperinci 如何设置把MyEclipse的Console输出到文件. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!