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
以上是如何設定把MyEclipse的Console輸出到文件的詳細內容。更多資訊請關注PHP中文網其他相關文章!