From 4b6eae2b88b5a5abc3bc7bcee205ecf033675a0f Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Fri, 20 Nov 2015 23:34:13 +0000
Subject: [PATCH] OPENDJ-2436 - Close and Delete temporary log files on success.

---
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/ControlPanelLog.java |   25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/ControlPanelLog.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/ControlPanelLog.java
index 3f74cf2..de4d5da 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/ControlPanelLog.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/ControlPanelLog.java
@@ -47,8 +47,7 @@
   private static FileHandler fileHandler;
 
   /**
-   * Creates a new file handler for writing log messages to the file indicated
-   * by <code>file</code>.
+   * Creates a new file handler for writing log messages to the file indicated by <code>file</code>.
    * @param file log file to which log messages will be written
    * @throws IOException if something goes wrong
    */
@@ -76,9 +75,8 @@
   }
 
   /**
-   * Writes messages under a given package in the file handler defined when
-   * calling initLogFileHandler.  Note that initLogFileHandler should be called
-   * before calling this method.
+   * Writes messages under a given package in the file handler defined when calling initLogFileHandler.
+   * Note that initLogFileHandler should be called before calling this method.
    * @param packageName the package name.
    * @throws IOException if something goes wrong
    */
@@ -108,12 +106,21 @@
     return logFile != null;
   }
 
-  private static String getInitialLogRecord() {
+  /** Closes the log file and deletes it. */
+  public static void closeAndDeleteLogFile()
+  {
+    if (logFile != null)
+    {
+      fileHandler.close();
+      logFile.delete();
+    }
+  }
+
+  private static String getInitialLogRecord()
+  {
     StringBuilder sb = new StringBuilder()
             .append("Application launched " +
-                    DateFormat.getDateTimeInstance(DateFormat.LONG,
-                                                   DateFormat.LONG).
-                            format(new Date()));
+                    DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(new Date()));
     return sb.toString();
   }
 

--
Gitblit v1.10.0