public synchronized void setFile(String fileName, boolean append, boolean bufferedIO, int bufferSize)
            throws IOException {
        LogLog.debug("setFile called: " + fileName + ", " + append);

        // It does not make sense to have immediate flush and bufferedIO.
        if (bufferedIO) {
            setImmediateFlush(false);
        }

        reset();
        FileOutputStream ostream = null;
        try {
            //
            // attempt to create file
            //
            ostream = new FileOutputStream(fileName, append);
        }
        catch (FileNotFoundException ex) {
            //
            // if parent directory does not exist then
            // attempt to create it and try to create file
            // see bug 9150
            //
            String parentName = new File(fileName).getParent();
            if (parentName != null) {
                File parentDir = new File(parentName);
                if (!parentDir.exists() && parentDir.mkdirs()) {
                    ostream = new FileOutputStream(fileName, append);
                }
                else {
                    throw ex;
                }
            }
            else {
                throw ex;
            }
        }

        if (bufferedIO) {
            this.out = new BufferedOutputStream(ostream, bufferSize);
        }
        else {
            this.out = ostream;
        }

        this.fileName = fileName;
        this.fileAppend = append;
        this.bufferedIO = bufferedIO;
        this.bufferSize = bufferSize;
        writeHeader();
        LogLog.debug("setFile ended");
    }
<p>
Sets and <i>opens</i> the file where the log output will go. The
specified file must be writable.

<p>
If there was already an opened file, then the previous file is closed
first.

<p>
<b>Do not use this method directly. To configure a FileAppender or one of
its subclasses, set its properties one by one and then call
activateOptions.</b>

@param fileName
           The path to the log file.
@param append
           If true will append to fileName. Otherwise will truncate
           fileName.
metamorphosis-client-extension/src/main/java/com/taobao/metamorphosis/client/extension/log4j/FileStreamAppender.java