giacomo 01/12/14 00:19:25
Modified: src/java/org/apache/log/output/io/rotate
UniqueFileStrategy.java
Log:
added new constructors to produce better readable file names
Revision Changes Path
1.2 +43 -2
jakarta-avalon-logkit/src/java/org/apache/log/output/io/rotate/UniqueFileStrategy.java
Index: UniqueFileStrategy.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-logkit/src/java/org/apache/log/output/io/rotate/UniqueFileStrategy.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UniqueFileStrategy.java 2001/08/21 04:18:53 1.1
+++ UniqueFileStrategy.java 2001/12/14 08:19:25 1.2
@@ -9,22 +9,50 @@
import java.io.File;
import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
/**
- * strategy for naming log files based on appending time suffix
+ * Strategy for naming log files based on appending time suffix.
+ * A file name can be based on simply appending the number of miliseconds
+ * since (not really sure) 1/1/1970.
+ * Other constructors accept a pattern of a <code>SimpleDateFormat</code>
+ * to form the appended string to the base file name as well as a suffix
+ * which should be appended last.
*
+ * A <code>new UniqueFileStrategy( new File("foo.", "yyyy-MM-dd", ".log"
)</code>
+ * object will return <code>File</code> objects with file names like
+ * <code>foo.2001-12-24.log</code>
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Bernhard Huber</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
*/
public class UniqueFileStrategy
implements FileStrategy
{
private File m_baseFile;
+ private SimpleDateFormat m_formatter;
+
+ private String m_suffix;
+
public UniqueFileStrategy( final File baseFile )
{
m_baseFile = baseFile;
}
+ public UniqueFileStrategy( final File baseFile, String pattern )
+ {
+ this( baseFile );
+ m_formatter = new SimpleDateFormat( pattern );
+ }
+
+ public UniqueFileStrategy( final File baseFile, String pattern, String
suffix )
+ {
+ this( baseFile, pattern );
+ m_suffix = suffix;
+ }
+
/**
* Calculate the real file name from the base filename.
*
@@ -34,7 +62,20 @@
{
final StringBuffer sb = new StringBuffer();
sb.append( m_baseFile );
- sb.append( System.currentTimeMillis() );
+ if( m_formatter == null )
+ {
+ sb.append( System.currentTimeMillis() );
+ }
+ else
+ {
+ final String dateString = m_formatter.format(new Date());
+ sb.append(dateString);
+ }
+
+ if( m_suffix != null ) {
+ sb.append( m_suffix );
+ }
+
return new File( sb.toString() );
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>