package loci.tests;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.FileAppender;
import org.apache.log4j.Layout;
import org.apache.log4j.spi.ErrorCode;

public class TimestampedLogFileAppender extends FileAppender {

    public TimestampedLogFileAppender() {
        
    }
    
    public TimestampedLogFileAppender(Layout layout, String filename,
                    boolean append, boolean bufferedIO, int bufferSize)
                    throws IOException {
        super(layout, filename, append, bufferedIO, bufferSize);
    }

    public TimestampedLogFileAppender(Layout layout, String filename,
                    boolean append) throws IOException {
        super(layout, filename, append);
    }

    public TimestampedLogFileAppender(Layout layout, String filename)
                    throws IOException {
        super(layout, filename);
    }

    @Override
    public void activateOptions() {
        if (this.fileName != null) {
            try {
                this.setFile(this.getNewFileName(), this.fileAppend,
                        this.bufferedIO, this.bufferSize);
            } catch (IOException e) {
                this.errorHandler.error(
                        "Error while adding timestamp to log name", e,
                        ErrorCode.FILE_OPEN_FAILURE);
            }
        }
    }

    private String getNewFileName() {
        final int lastDotIndex = this.fileName.lastIndexOf(".");
        String newFileName = "";

        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy-HH-mm-ss");
        String timestamp = "-" + sdf.format(new Date());

        if (lastDotIndex != -1) {
            newFileName = this.fileName.substring(0, lastDotIndex) +
                    timestamp + this.fileName.substring(lastDotIndex);
        } else {
            newFileName = this.fileName + timestamp;
        }
        return newFileName;
    }
}
@@ -1,8 +1,934 @@
+/*%0A * #%25L%0A * OME Bio-Formats manual and automated test suite.%0A * %25%25%0A * Copyright (C) 2006 - 2012 Open Microscopy Environment:%0A *   - Board of Regents of the University of Wisconsin-Madison%0A *   - Glencoe Software, Inc.%0A *   - University of Dundee%0A * %25%25%0A * This program is free software: you can redistribute it and/or modify%0A * it under the terms of the GNU General Public License as%0A * published by the Free Software Foundation, either version 2 of the%0A * License, or (at your option) any later version.%0A *%0A * This program is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A * GNU General Public License for more details.%0A *%0A * You should have received a copy of the GNU General Public%0A * License along with this program.  If not, see%0A * %3Chttp://www.gnu.org/licenses/gpl-2.0.html%3E.%0A * #L%25%0A */%0A%0A
 package 

Add copyright header to log file appender