跳轉到內容

WebObjects/Web 應用程式/部署/日誌記錄

來自華夏公益教科書,開放的書籍,開放的世界

日誌輪換

[編輯 | 編輯原始碼]

邁克·基南伯格

[編輯 | 編輯原始碼]

我不記得是誰給了我這個基本起點,但我認為可能是喬納森之一。您需要更改檔名以使其在非 Unix 部署系統下工作。

您會發現先進入編輯模式更容易複製原始碼。

   public static void main(String argv[])
   {
       try
       {
           String baseOutputPath = null;
           
           //look for a -WOOutputPath argument
           for (int i=0; i<argv.length; i++) {
               if (  argv[i].equals("-WOOutputPath") &&
                   !argv[i+1].equals("/dev/null")  ) {
                   String outputPath = argv[i+1];
                   baseOutputPath = outputPath;
                   java.io.File outputFile = new java.io.File(outputPath);
                   if (outputFile.exists()) {
                       // move old file out of way to new location,
                       //name based on existing name with an appended timestamp
 
                       // Format the current time.
                       java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
                       java.util.GregorianCalendar now = new java.util.GregorianCalendar();
                       String dateSuffix = ".bck-" + formatter.format(now.getTime());
                       System.err.println("new name: " + outputPath + dateSuffix);
                       java.io.File renamedFile = new java.io.File(outputPath + dateSuffix);
                       outputFile.renameTo(renamedFile);
                   }
                   break;
               }
           }
       }
       catch (Throwable e) {
           //just so any Throwables generated in trying to do this don't
           //keep our app from launching.
           System.err.println("Ignoring: " + e);
       }
 
       WOApplication.main(argv, Application.class);
   }
華夏公益教科書