Index: src/main/php/appenders/LoggerAppenderDailyFile.php =================================================================== --- src/main/php/appenders/LoggerAppenderDailyFile.php (revision 979037) +++ src/main/php/appenders/LoggerAppenderDailyFile.php (working copy) @@ -58,11 +58,11 @@ } /** - * Sets date format for the file name. - * @param string $format a regular date() string format + * Sets date pattern for the file name. + * @param string $datePattern a {@link PHP_MANUAL#date()} pattern */ - public function setDatePattern($format) { - $this->datePattern = $format; + public function setDatePattern($datePattern) { + $this->datePattern = $datePattern; } /** @@ -73,20 +73,14 @@ } /** - * The File property takes a string value which should be the name of the file to append to. - * Sets and opens the file where the log output will go. + * 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() { - $numargs = func_num_args(); - $args = func_get_args(); - - if($numargs == 1 and is_string($args[0])) { - parent::setFile( sprintf((string)$args[0], date($this->getDatePattern())) ); - } else if ($numargs == 2 and is_string($args[0]) and is_bool($args[1])) { - parent::setFile( sprintf((string)$args[0], date($this->getDatePattern())), $args[1] ); - } + public function setFile($file) { + $date = date($this->getDatePattern()); + $file = sprintf($file, $date); + parent::setFile(sprintf($file, $date)); } - } Index: src/main/php/appenders/LoggerAppenderFile.php =================================================================== --- src/main/php/appenders/LoggerAppenderFile.php (revision 979037) +++ src/main/php/appenders/LoggerAppenderFile.php (working copy) @@ -25,7 +25,7 @@ * * - layout - Sets the layout class for this appender * - file - The target file to write to - * - filename - The target file to write to + * - filename - The target file to write to (deprecated, use "file" instead) * - append - Sets if the appender should append to the end of the file or overwrite content ("true" or "false") * * An example php file: @@ -49,7 +49,7 @@ /** * @var string the file name used to append events */ - protected $fileName; + protected $file; /** * @var mixed file resource */ @@ -61,20 +61,20 @@ } public function __destruct() { - $this->close(); - } - + $this->close(); + } + public function activateOptions() { - $fileName = $this->getFile(); + $file = $this->getFile(); - if(!is_file($fileName)) { - $dir = dirname($fileName); + if(!is_file($file)) { + $dir = dirname($file); if(!is_dir($dir)) { mkdir($dir, 0777, true); } } - $this->fp = fopen($fileName, ($this->getAppend()? 'a':'w')); + $this->fp = fopen($file, ($this->getAppend()? 'a':'w')); if($this->fp) { if(flock($this->fp, LOCK_EX)) { if($this->getAppend()) { @@ -117,54 +117,54 @@ } /** - * Sets and opens the file where the log output will go. - * - * This is an overloaded method. It can be called with: - * - setFile(string $fileName) to set filename. - * - setFile(string $fileName, boolean $append) to set filename and append. - * - * TODO: remove overloading. Use only file as alias to filename + * Sets the path to the target file where the log output will go. + * @param string $file File path. */ - public function setFile() { - $numargs = func_num_args(); - $args = func_get_args(); - - if($numargs == 1 and is_string($args[0])) { - $this->setFileName($args[0]); - } else if ($numargs >=2 and is_string($args[0]) and is_bool($args[1])) { - $this->setFile($args[0]); - $this->setAppend($args[1]); - } + public function setFile($file) { + $this->file = $file; } /** + * Returns the path to the target file. * @return string */ public function getFile() { - return $this->getFileName(); + return $this->file; } /** + * Returns the append flag. * @return boolean */ public function getAppend() { return $this->append; } + /** + * Sets the append flag, if set to TRUE the appender will append to + * the file, otherwise it will overwrite the file each time it is run. + * @param boolean $flag The append flag. + */ public function setAppend($flag) { $this->append = LoggerOptionConverter::toBoolean($flag, true); } + /** + * Sets the path to the target file where the log output will go. + * @param string $fileName File path. + * @deprecated Use setFile() instead. + */ public function setFileName($fileName) { - $this->fileName = $fileName; + trigger_error("The 'fileName' parameter is deprecated. Please use 'file' instead.", E_USER_WARNING); + $this->setFile($fileName); } /** - * @return string + * Returns the path to the target file. + * @return string File path. + * @deprecated Use getFile() instead. */ public function getFileName() { - return $this->fileName; + return $this->getFile(); } - - } Index: src/main/php/appenders/LoggerAppenderRollingFile.php =================================================================== --- src/main/php/appenders/LoggerAppenderRollingFile.php (revision 979037) +++ src/main/php/appenders/LoggerAppenderRollingFile.php (working copy) @@ -26,13 +26,13 @@ * * - layout - Sets the layout class for this appender * - file - The target file to write to - * - filename - The target file to write to + * - filename - The target file to write to (deprecated, use file instead) * - append - Sets if the appender should append to the end of the file or overwrite content ("true" or "false") * - maxBackupIndex - Set the maximum number of backup files to keep around (int) * - maxFileSize - Set the maximum size that the output file is allowed to * reach before being rolled over to backup files. * Suffixes like "KB", "MB" or "GB" are allowed, f. e. "10KB" is interpreted as 10240 - * - maximumFileSize - Alias to MaxFileSize + * - maximumFileSize - Alias to maxFileSize (deprecated, use maxFileSize instead) * *
Contributors: Sergio Strampelli.
* @@ -99,15 +99,6 @@ } /** - * Get the maximum size that the output file is allowed to reach - * before being rolled over to backup files. - * @return integer - */ - private function getMaximumFileSize() { - return $this->maxFileSize; - } - - /** * Implements the usual roll over behaviour. * *If MaxBackupIndex is positive, then files File.1, ..., File.MaxBackupIndex -1 are renamed to File.2, ..., File.MaxBackupIndex. @@ -145,13 +136,13 @@ $this->setFile($fileName, false); } - public function setFileName($fileName) { - $this->fileName = $fileName; + public function setFile($file) { + $this->file = $file; // As LoggerAppenderFile does not create the directory, it has to exist. // realpath() fails if the argument does not exist so the filename is separated. - $this->expandedFileName = realpath(dirname($fileName)); - if ($this->expandedFileName === false) throw new Exception("Directory of $fileName does not exist!"); - $this->expandedFileName .= DIRECTORY_SEPARATOR . basename($fileName); + $this->expandedFileName = realpath(dirname($file)); + if ($this->expandedFileName === false) throw new Exception("Directory of $file does not exist!"); + $this->expandedFileName .= DIRECTORY_SEPARATOR . basename($file); } @@ -171,6 +162,13 @@ $this->maxBackupIndex = abs((int)$maxBackups); } } + + /** + * @return Returns the maximum number of backup files to keep around. + */ + public function getMaxBackupIndex() { + return $this->maxBackupIndex; + } /** * Set the maximum size that the output file is allowed to reach @@ -178,16 +176,26 @@ * * @param mixed $maxFileSize * @see setMaxFileSize() - * @deprecated + * @deprecated This method is deprecated. Use setMaxFileSize() instead. */ public function setMaximumFileSize($maxFileSize) { + trigger_error("The 'maximumFileSize' parameter is deprecated. Please use 'maxFileSize' instead.", E_USER_WARNING); return $this->setMaxFileSize($maxFileSize); } + + /** + * @return Returns the maximum size that the output file is allowed to + * reach before being rolled over to backup files. + * @deprecated This method is deprecated. Use getMaxFileSize() instead. + */ + public function getMaximumFileSize() { + return $this->maxFileSize; + } /** * Set the maximum size that the output file is allowed to reach * before being rolled over to backup files. - *
In configuration files, the MaxFileSize option takes an + *
In configuration files, the maxFileSize option takes an * long integer in the range 0 - 2^63. You can specify the value * with the suffixes "KB", "MB" or "GB" so that the integer is * interpreted being expressed respectively in kilobytes, megabytes @@ -217,6 +225,14 @@ } return $this->maxFileSize; } + + /** + * @return Returns the maximum size that the output file is allowed to reach + * before being rolled over to backup files. + */ + public function getMaxFileSize() { + return $this->maxFileSize; + } /** * @param LoggerLoggingEvent $event Index: src/test/php/appenders/LoggerAppenderFileTest.php =================================================================== --- src/test/php/appenders/LoggerAppenderFileTest.php (revision 998456) +++ src/test/php/appenders/LoggerAppenderFileTest.php (working copy) @@ -40,7 +40,7 @@ "my message"); $appender = new LoggerAppenderFile("mylogger"); - $appender->setFileName('../../../target/temp/phpunit/TEST.txt'); + $appender->setFile('../../../target/temp/phpunit/TEST.txt'); $appender->setLayout($layout); $appender->activateOptions(); $appender->append($event); Index: src/test/php/appenders/LoggerAppenderRollingFileTest.php =================================================================== --- src/test/php/appenders/LoggerAppenderRollingFileTest.php (revision 998456) +++ src/test/php/appenders/LoggerAppenderRollingFileTest.php (working copy) @@ -74,7 +74,7 @@ public function testSetFileName() { $appender = new LoggerAppenderRollingFile("mylogger"); - $appender->setFileName($this->dir.'/../././phpunit/doesnotexist.log'); + $appender->setFile($this->dir.'/../././phpunit/doesnotexist.log'); $expandedFileName = self::readAttribute($appender, 'expandedFileName'); $expectedFilePattern = '/' . implode(preg_quote(DIRECTORY_SEPARATOR, '/'), array('target', 'phpunit', 'doesnotexist\.log')) . '$/'; @@ -85,9 +85,9 @@ $layout = new LoggerLayoutSimple(); $appender = new LoggerAppenderRollingFile("mylogger"); - $appender->setFileName($this->dir.'/TEST-rolling.txt'); + $appender->setFile($this->dir.'/TEST-rolling.txt'); $appender->setLayout($layout); - $appender->setMaximumFileSize('1KB'); + $appender->setMaxFileSize('1KB'); $appender->setMaxBackupIndex(2); $appender->activateOptions();