package lwjar.precompile;

import lwjar.GlobalOption;
import lwjar.primitive.Directory;
import lwjar.primitive.RelativePath;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

class ErrorLogFile {
    private final static String FILE_NAME = "compile-errors.log";
    private final Path file;

    ErrorLogFile(OutputDirectory outputDirectory) {
        this.file = outputDirectory.resolve(FILE_NAME).getPath();
    }
    
    void append(String text) {
        if (text.isEmpty()) {
            return;
        }

        try {
            Files.write(this.file, text.getBytes(GlobalOption.getEncoding()), StandardOpenOption.APPEND, StandardOpenOption.CREATE);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
}

package lwjar.precompile;

import lwjar.GlobalOption;
import lwjar.primitive.ProcessingFile;
import lwjar.primitive.RelativePath;

import java.nio.file.Paths;
import java.util.Objects;

class ErrorLogFile {
    private static int n = 1;
    private final static String FILE_NAME = "compile-errors-%d.log";
    private final OutputDirectory outputDirectory;
    
    ErrorLogFile(OutputDirectory outputDirectory) {
        this.outputDirectory = Objects.requireNonNull(outputDirectory);
    }
    
    synchronized void write(String text) {
        if (text.isEmpty()) {
            return;
        }

        String fileName = String.format(FILE_NAME, n);
        ProcessingFile file = this.outputDirectory.resolveFile(new RelativePath(Paths.get(fileName)));
        file.write(text, GlobalOption.getEncoding());
        
        n++;
    }
}

split compile error file