<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 97,  comments - 93,  trackbacks - 0

    //*******************The Log class
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.uitl.Date;
    import java.text.DateFormat;

    public class Log{
       private static final String filePath = PropertyReader.getResource("Log_File_Path");//Supposing we have define in the last ProperyReader class and the file
      
       public static final String EXCEPTION                  =   "Exception";
       public static final String CREATE_STAFF           =   "Create Staff";
       public static final String EDIT_STAFF                 =   "Edit Staff";
       public static final String DELETE_STAFF            =   "Delete Staff";
       public static final String RECORD_HAS_EXIST  =   "Record Has Exist";

       public static void log(String msg_type, Exception e){
          StringBuffer errMsg = new StringBuffer(e.toString);
         
          for(int i=0;i<e.getStackTrace().length;i++){
             errMsg.append("\n\t at");
             errMsg.append(e.getStackTrace()[i].toString);
          }
          log(msg_type,errMsg.toString());
          OptionPanel.showErrMsg("Sorry,System may have an error \n System will exit");
          System.exit(-1);
       }

      public static void log(String msg.type,Staff staff){
         String msg = null;
         if(msg_type == CREATE_STAFF){
             msg = staff.toString() + "has benn created";
         }else if(msg_type == EDIT_STAFF){
             msg = staff.toString() + "has been Changed";
         }else if(msg_type == DELETE_STAFF){
             msg = staff.toString() + "has been Deleted";
         }else if(msg_type == RECORD_HAS_EXIST){
             msg = staff.toString() + "has exist in the database";
         }
         log(msg_type,msg);
      }

      private static void log(String msg_type,String msg){
          BufferedWriter out = null;
          DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
         
          try{
            out = new BufferedWriter(new FileWriter(getLogFilePath(),true));//如果為 true,則將字節寫入文件末尾處,而不是寫入文件開始處
            out.write("["+df.format(new Date()) + "] <" + msg_type + "> :" + msg);
            out.newline();
            out.newline();
          }catch(IOException e){
              e.printStackTrace();
          }finally{
             try{
               if(out!=null){
                  out.close();
               }
             }catch(IOException e){
                e.printStackTrace();
             }
          }
      }

      private static String getLogFilePath(){
         File logDir = new File(filePath);
         if(!logDir.exists()){
           logDir.mkdir();
         }
        
         int i = 1;
         String fileName = filePath + "log_";
         File file = new File(fileName + i + ".txt");
       
         while(file.exists() && file.length() > 30000L) {
             i++;
             file = new File(fileName + i + ".txt");
         }
       
          return fileName + i + ".txt"
      }
    }

    //*****************************The OptionPanel Dialog Class for the Log Class
    import javax.swing.JOptionPane;

    public class OptionPanel {
       private static final String appTitle = PropertyReader.getResource("App_Title");//suposing the file has been established and the property app-title stands for the name of application
       private static final MainFrame frame = MainFrame.getMainFrame();

       public static void showWarningMsg(String msg){
          JOptionPane.showMessageDialog(frame,msg,appTitle,JOptionPane.WARNING_MESSAGE);
       }
       public static void showErrMsg(String msg){
           JOptionPane.showMessageDialog(frame,msg,appTitle,JOptionPane.Error_MESSAGE);
       }
       public static int showConfirmMsg(String msg){
            return JOptionPane.showConfirmDialog(frame,msg,appTitle,JOptionPane.YES_NO_OPTON,JOptionPane.QUESTION_MESSAGE);
       }
    }

    posted on 2007-04-05 10:01 wqwqwqwqwq 閱讀(872) 評論(1)  編輯  收藏 所屬分類: Simple Java

    FeedBack:
    # re: Write a Log && Use the Properties
    2007-04-07 18:29 | 曲強
    我也叫曲強,我QQ139876554,有時間加我吧  回復  更多評論
      
    <2007年4月>
    25262728293031
    1234567
    891011121314
    15161718192021
    22232425262728
    293012345




    常用鏈接

    留言簿(10)

    隨筆分類(95)

    隨筆檔案(97)

    文章檔案(10)

    相冊

    J2ME技術網站

    java技術相關

    mess

    搜索

    •  

    最新評論

    閱讀排行榜

    校園夢網網絡電話,中國最優秀的網絡電話
    主站蜘蛛池模板: 亚洲一区二区无码偷拍| 久久久久亚洲AV成人无码网站| 亚洲制服丝袜第一页| 91短视频在线免费观看| 亚洲一区二区成人| 99热这里有免费国产精品| 亚洲av无码一区二区三区不卡| 国产成人无码区免费网站| 国产亚洲A∨片在线观看| 中文字幕久精品免费视频| 日韩精品亚洲人成在线观看| 99久久免费看国产精品| 亚洲精品在线网站| 中文字幕人成无码免费视频| 亚洲综合小说另类图片动图| 国产精品免费视频网站| 成年免费大片黄在线观看com| 亚洲国产成人VA在线观看| yellow免费网站| 久久精品国产精品亚洲色婷婷| 桃子视频在线观看高清免费视频| 亚洲日本在线播放| 免费观看的a级毛片的网站| 全部在线播放免费毛片| 亚洲人成网站在线观看播放| 一级毛片免费不卡在线| 亚洲精品第一综合99久久| 国产免费av片在线播放| 久久一区二区三区免费| 亚洲精品高清国产麻豆专区| 女人18毛片水真多免费看 | 亚洲一区二区三区偷拍女厕| 久艹视频在线免费观看| 亚洲卡一卡二卡乱码新区| 亚洲国产成人精品久久久国产成人一区二区三区综 | 亚洲第一页日韩专区| 久久久久久久岛国免费播放 | 亚洲免费在线视频| 国产成人精品日本亚洲18图| 亚洲国产精品无码久久九九| 一区二区三区观看免费中文视频在线播放|