logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ihabu...@apache.org
Subject svn commit: r1382243 - in /logging/log4php/trunk/src/main/php/appenders: LoggerAppenderFile.php LoggerAppenderRollingFile.php
Date Sat, 08 Sep 2012 07:51:18 GMT
Author: ihabunek
Date: Sat Sep  8 07:51:18 2012
New Revision: 1382243

URL: http://svn.apache.org/viewvc?rev=1382243&view=rev
Log:
Fixed a bug in file appenders where they would attempt to write the log event even if opening
of file was unsuccessful.

Modified:
    logging/log4php/trunk/src/main/php/appenders/LoggerAppenderFile.php
    logging/log4php/trunk/src/main/php/appenders/LoggerAppenderRollingFile.php

Modified: logging/log4php/trunk/src/main/php/appenders/LoggerAppenderFile.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderFile.php?rev=1382243&r1=1382242&r2=1382243&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderFile.php (original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderFile.php Sat Sep  8 07:51:18
2012
@@ -75,6 +75,8 @@ class LoggerAppenderFile extends LoggerA
 	/**
 	 * 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 @@ class LoggerAppenderFile extends LoggerA
 				if ($success === false) {
 					$this->warn("Failed creating target directory [$dir]. Closing appender.");
 					$this->closed = true;
-					return;
+					return false;
 				}
 			}
 		}
@@ -97,8 +99,9 @@ class LoggerAppenderFile extends LoggerA
 		$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 @@ class LoggerAppenderFile extends LoggerA
 	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 @@ class LoggerAppenderFile extends LoggerA
 		if (is_resource($this->fp)) {
 			$this->write($this->layout->getFooter());
 			fclose($this->fp);
+			unset($this->fp);
 		}
 		$this->closed = true;
 	}

Modified: logging/log4php/trunk/src/main/php/appenders/LoggerAppenderRollingFile.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderRollingFile.php?rev=1382243&r1=1382242&r2=1382243&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderRollingFile.php (original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderRollingFile.php Sat Sep  8
07:51:18 2012
@@ -182,7 +182,9 @@ class LoggerAppenderRollingFile extends 
 	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



Mime
View raw message