public void printStackTrace(Exception exception) {
        exception.printStackTrace();
        if (writeToFile) {
            checkLogFile();
            exception.printStackTrace(printWriter);
            printWriter.flush();
        }
    }