logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ihabu...@apache.org
Subject svn commit: r1211935 - /logging/log4php/trunk/src/main/php/appenders/LoggerAppenderDailyFile.php
Date Thu, 08 Dec 2011 15:37:03 GMT
Author: ihabunek
Date: Thu Dec  8 15:37:03 2011
New Revision: 1211935

URL: http://svn.apache.org/viewvc?rev=1211935&view=rev
Log:
LOG4PHP-114: Order of params in LoggerAppenderDailyFile configuration is no longer significant

Modified:
    logging/log4php/trunk/src/main/php/appenders/LoggerAppenderDailyFile.php

Modified: logging/log4php/trunk/src/main/php/appenders/LoggerAppenderDailyFile.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderDailyFile.php?rev=1211935&r1=1211934&r2=1211935&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderDailyFile.php (original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderDailyFile.php Thu Dec  8 15:37:03
2011
@@ -74,15 +74,37 @@ class LoggerAppenderDailyFile extends Lo
 		return $this->datePattern;
 	}
 	
-	/**
-	 * Similar to the parent method, but replaces "%s" in the file name with 
-	 * the current date in format specified by $datePattern. 
-	 *
-	 * @see LoggerAppenderFile::setFile()
-	 */
-	public function setFile($file) {
+	/** 
+	 * Similar to parent method, but but replaces "%s" in the file name with 
+	 * the current date in format specified by the 'datePattern' parameter.
+	 */ 
+	public function activateOptions() {
+		$fileName = $this->getFile();
 		$date = date($this->getDatePattern());
-		$file = sprintf($file, $date);
-		parent::setFile(sprintf($file, $date));
+		$fileName = sprintf($fileName, $date);
+		
+		if(!is_file($fileName)) {
+			$dir = dirname($fileName);
+			if(!is_dir($dir)) {
+				mkdir($dir, 0777, true);
+			}
+		}
+	
+		$this->fp = fopen($fileName, ($this->getAppend()? 'a':'w'));
+		if($this->fp) {
+			if(flock($this->fp, LOCK_EX)) {
+				if($this->getAppend()) {
+					fseek($this->fp, 0, SEEK_END);
+				}
+				fwrite($this->fp, $this->layout->getHeader());
+				flock($this->fp, LOCK_UN);
+				$this->closed = false;
+			} else {
+				// TODO: should we take some action in this case?
+				$this->closed = true;
+			}
+		} else {
+			$this->closed = true;
+		}
 	}
 }



Mime
View raw message