Go to the documentation of this file.00001 package myShell;
00002
00003 import java.io.BufferedWriter;
00004 import java.io.FileWriter;
00005 import java.util.Calendar;
00006
00013 public class LogWriter {
00014
00015
00016
00017
00018
00022 String logName;
00023
00024
00025
00026
00027
00028
00032 public LogWriter()
00033 {
00034 Calendar cal = Calendar.getInstance();
00035 String date = cal.get(Calendar.DATE) + "-" + (cal.get(Calendar.MONTH)+1) + "-" +
00036 cal.get(Calendar.YEAR) + "-(" + cal.get(Calendar.HOUR_OF_DAY) + ":" +
00037 cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND) + ")";
00038 this.logName = "../data/log/" + date + ".log" ;
00039 this.append(" ----- started at : " + date + "\n\n");
00040 }
00041
00042
00043
00044
00045
00046
00051 public void append(String line)
00052 {
00053 System.out.println(line);
00054 try
00055 {
00056 BufferedWriter logFile = new BufferedWriter
00057 (new FileWriter(this.logName,true));
00058 logFile.write(line);
00059 logFile.newLine();
00060 logFile.close();
00061 }
00062 catch (Exception e) { e.printStackTrace(); }
00063 }
00064
00065
00069 public void finish()
00070 {
00071 Calendar cal = Calendar.getInstance();
00072 String date = cal.get(Calendar.DATE) + "-" + (cal.get(Calendar.MONTH)+1) + "-" +
00073 cal.get(Calendar.YEAR) + "-(" + cal.get(Calendar.HOUR_OF_DAY) + ":" +
00074 cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND) + ")";
00075 append("\n ----- finished at : " + date);
00076 }
00077 }