// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.XMLFormatter;

public class AppendToLog {
    public static void main(String[] args) throws Exception {
        Logger logger = Logger.getLogger("Test");
        logger.addHandler(new HackFileHandler("C:\\hacklog.log", Level.FINE));
        logger.info("This is a test");
    }
}

class HackFileHandler extends FileHandler {
    public HackFileHandler() throws IOException, SecurityException {
        this("NUL:", Level.INFO);
    }
    public HackFileHandler(String fnm, Level lvl) throws IOException, SecurityException {
        super(fnm, true);
        setLevel(lvl);
        // start hack
        long len = (new File(fnm)).length();
        if(len > 7) {
            super.close();
            RandomAccessFile raf = new RandomAccessFile(fnm, "rw");
            raf.setLength(len - 7);
            raf.close();
            setFormatter(new HackFormatter());
            setOutputStream(new FileOutputStream(fnm, true));
        }
        // slut hack
    }
}

class HackFormatter extends XMLFormatter {
    public String getHead(Handler h) {
        return "";
    }
}
