public synchronized void setFile(String fileName, boolean append, boolean bufferedIO,
    int bufferSize) throws IOException {

    // 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;
      }
    }
    Writer fw = createWriter(ostream);
    if (bufferedIO) {
      fw = new BufferedWriter(fw, bufferSize);
    }
    this.setQWForFiles(fw);
    this.fileName = fileName;
    this.fileAppend = append;
    this.bufferedIO = bufferedIO;
    this.bufferSize = bufferSize;
    writeHeader();
  }
<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.
hbase-logging/src/test/java/org/apache/log4j/FileAppender.java