Fixed a bug in file appenders where they would attempt to write the log event even if opening of file was unsuccessful.

git-svn-id: https://svn.apache.org/repos/asf/logging/log4php/trunk@1382243 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/php/appenders/LoggerAppenderFile.php b/src/main/php/appenders/LoggerAppenderFile.php
index 078212c..c9aad10 100644
--- a/src/main/php/appenders/LoggerAppenderFile.php
+++ b/src/main/php/appenders/LoggerAppenderFile.php
@@ -75,6 +75,8 @@
 	/**
 	 * Acquires the target file resource, creates the destination folder if 
 	 * necessary. Writes layout header to file.
+	 * 
+	 * @return boolean FALSE if opening failed
 	 */
 	protected function openFile() {
 		$file = $this->getTargetFile();
@@ -88,7 +90,7 @@
 				if ($success === false) {
 					$this->warn("Failed creating target directory [$dir]. Closing appender.");
 					$this->closed = true;
-					return;
+					return false;
 				}
 			}
 		}
@@ -97,8 +99,9 @@
 		$this->fp = fopen($file, $mode);
 		if ($this->fp === false) {
 			$this->warn("Failed opening target file. Closing appender.");
+			$this->fp = null;
 			$this->closed = true;
-			return;
+			return false;
 		}
 		
 		// Required when appending with concurrent access
@@ -117,7 +120,9 @@
 	protected function write($string) {
 		// Lazy file open
 		if(!isset($this->fp)) {
-			$this->openFile();
+			if ($this->openFile() === false) {
+				return; // Do not write if file open failed.
+			}
 		}
 		
 		if ($this->locking) {
@@ -159,6 +164,7 @@
 		if (is_resource($this->fp)) {
 			$this->write($this->layout->getFooter());
 			fclose($this->fp);
+			unset($this->fp);
 		}
 		$this->closed = true;
 	}
diff --git a/src/main/php/appenders/LoggerAppenderRollingFile.php b/src/main/php/appenders/LoggerAppenderRollingFile.php
index f3d06ce..5b262d7 100644
--- a/src/main/php/appenders/LoggerAppenderRollingFile.php
+++ b/src/main/php/appenders/LoggerAppenderRollingFile.php
@@ -182,7 +182,9 @@
 	protected function write($string) {
 		// Lazy file open
 		if(!isset($this->fp)) {
-			$this->openFile();
+			if ($this->openFile() === false) {
+				return; // Do not write if file open failed.
+			}
 		}
 		
 		// Lock the file while writing and possible rolling over