From c501e72992fa82c0b37f224e7b28ff21a8f62a5a Mon Sep 17 00:00:00 2001 From: Frank Maritato Date: Fri, 15 Jan 2010 21:24:51 +0000 Subject: [PATCH] if when rotating the file, it exists already, prepend the date to the old file and rename it first. git-svn-id: https://lwes.svn.sourceforge.net/svnroot/lwes/lwes-journaller-java/trunk@391 a2f82657-cdd2-4550-bd36-68a8e7111808 --- .../org/lwes/journaller/handler/GZIPEventHandler.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/org/lwes/journaller/handler/GZIPEventHandler.java b/src/main/java/org/lwes/journaller/handler/GZIPEventHandler.java index 74df9f9..7e5d0e3 100644 --- a/src/main/java/org/lwes/journaller/handler/GZIPEventHandler.java +++ b/src/main/java/org/lwes/journaller/handler/GZIPEventHandler.java @@ -13,10 +13,12 @@ import org.lwes.journaller.event.Rotate; import org.lwes.journaller.util.EventHandlerUtil; import org.lwes.listener.DatagramQueueElement; +import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.net.DatagramPacket; import java.nio.ByteBuffer; +import java.util.Calendar; import java.util.zip.GZIPOutputStream; /** @@ -49,6 +51,19 @@ public class GZIPEventHandler extends AbstractFileEventHandler { * @throws IOException if there is a problem opening a handle to the file. */ protected void createFileHandle() throws IOException { + File newFile = new File(getFilename()); + if (newFile.exists()) { + Calendar c = Calendar.getInstance(); + StringBuilder buf = new StringBuilder() + .append(c.get(Calendar.YEAR)).append(c.get(Calendar.MONTH)) + .append(c.get(Calendar.DAY_OF_MONTH)).append(c.get(Calendar.HOUR_OF_DAY)) + .append(c.get(Calendar.MINUTE)) + .append(getFilename()); + boolean succeeded = newFile.renameTo(new File(buf.toString())); + if (!succeeded) { + log.error("File rename failed. "+newFile.getAbsolutePath()); + } + } out = new GZIPOutputStream(new FileOutputStream(getFilename(), true)); if (log.isDebugEnabled()) { log.debug("Created a new log file: " + getFilename()); -- 2.11.4.GIT