Author: ihabunek
Date: Sun Jan 16 09:29:43 2011
New Revision: 1059522
URL: http://svn.apache.org/viewvc?rev=1059522&view=rev
Log:
LOG4PHP-131: File appenders parameters
* Replaced $fileName param with $file (as stated in docs)
* Removed overloading of setFile()
* Added missing getters for all configurable parameters
Modified:
logging/log4php/trunk/src/changes/changes.xml
logging/log4php/trunk/src/main/php/appenders/LoggerAppenderDailyFile.php
logging/log4php/trunk/src/main/php/appenders/LoggerAppenderFile.php
logging/log4php/trunk/src/main/php/appenders/LoggerAppenderRollingFile.php
logging/log4php/trunk/src/test/php/appenders/LoggerAppenderFileTest.php
logging/log4php/trunk/src/test/php/appenders/LoggerAppenderRollingFileTest.php
Modified: logging/log4php/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/logging/log4php/trunk/src/changes/changes.xml?rev=1059522&r1=1059521&r2=1059522&view=diff
==============================================================================
--- logging/log4php/trunk/src/changes/changes.xml (original)
+++ logging/log4php/trunk/src/changes/changes.xml Sun Jan 16 09:29:43 2011
@@ -24,6 +24,7 @@
</properties>
<body>
<release version="2.1" description="Stabilizing">
+ <action type="fix" issue="LOG4PHP-131" by="Ivan Habunek">File
appenders parameters (removed overloading of setFile()).</action>
<action type="fix" issue="LOG4PHP-133" by="Dmitry
Katemirov,Ivan Habunek">PDO appender doesn't close connections</action>
<action type="fix" by="Ivan Habunek">Replaced calls to
deprecated PHPUnit method assertTypeOf() with assertInternalType() and
assertInstanceOf().</action>
<action type="fix" issue="LOG4PHP-104" by="Ivan
Habunek">Refactored LoggerNDC and added tests</action>
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=1059522&r1=1059521&r2=1059522&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderDailyFile.php
(original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderDailyFile.php
Sun Jan 16 09:29:43 2011
@@ -24,11 +24,17 @@
* The file is rolled over once a day. That means, for each day a new file
* is created. A formatted version of the date pattern is used as to create
* the file name using the {@link PHP_MANUAL#sprintf} function.
+ *
+ * This appender uses a layout.
*
- * - layout - Sets the layout class for this appender
- * - datePattern - Sets date format for the file name. Should be set
before $file!
- * - file - The target file name. Should contain a '%s' which
gets substituted by the date.
- * - append - Sets if the appender should append to the end of the
file or overwrite content ("true" or "false")
+ * Configurable parameters for this appender are:
+ * - datePattern - The date format for the file name. Should be set before
+ * $file. Default value: "Ymd".
+ * - file - The path to the target log file. The filename should
+ * contain a '%s' which will be substituted by the date.
+ * - append - Sets if the appender should append to the end of the
+ * file or overwrite content ("true" or "false"). Default
+ * value: true.
*
* An example php file:
*
@@ -58,35 +64,29 @@ class LoggerAppenderDailyFile extends Lo
}
/**
- * Sets date format for the file name.
- * @param string $format a regular date() string format
- */
- public function setDatePattern($format) {
- $this->datePattern = $format;
+ * Sets date format for the file name.
+ * @param string $datePattern a regular date() string format
+ */
+ public function setDatePattern($datePattern) {
+ $this->datePattern = $datePattern;
}
/**
- * @return string returns date format for the filename
- */
+ * @return string returns date format for the filename
+ */
public function getDatePattern() {
return $this->datePattern;
}
/**
- * 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.
- *
- * @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] );
- }
- }
-
+ * 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) {
+ $date = date($this->getDatePattern());
+ $file = sprintf($file, $date);
+ parent::setFile(sprintf($file, $date));
+ }
}
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=1059522&r1=1059521&r2=1059522&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderFile.php
(original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderFile.php Sun Jan
16 09:29:43 2011
@@ -21,12 +21,12 @@
/**
* FileAppender appends log events to a file.
*
- * Configurable parameters for this appender are:
+ * This appender uses a layout.
*
- * - layout - Sets the layout class for this appender
- * - file - The target file to write to
- * - filename - The target file to write to
- * - append - Sets if the appender should append to the end of the
file or overwrite content ("true" or "false")
+ * Configurable parameters for this appender are:
+ * - file - 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:
*
@@ -50,8 +50,8 @@ class LoggerAppenderFile extends LoggerA
/**
* @var string the file name used to append events
*/
- protected $fileName;
-
+ protected $file;
+
/**
* @var mixed file resource
*/
@@ -119,31 +119,18 @@ class LoggerAppenderFile extends LoggerA
}
/**
- * 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
- */
- 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]);
- }
+ * Sets the file where the log output will go.
+ * @param string $file
+ */
+ public function setFile($file) {
+ $this->file = $file;
}
/**
* @return string
*/
public function getFile() {
- return $this->getFileName();
+ return $this->file;
}
/**
@@ -157,15 +144,21 @@ class LoggerAppenderFile extends LoggerA
$this->append = LoggerOptionConverter::toBoolean($flag, true);
}
+ /**
+ * Sets the file where the log output will go.
+ * @param string $fileName
+ * @deprecated Use setFile() instead.
+ */
public function setFileName($fileName) {
- $this->fileName = $fileName;
+ $this->setFile($fileName);
}
/**
* @return string
+ * @deprecated Use getFile() instead.
*/
public function getFileName() {
- return $this->fileName;
+ return $this->getFile();
}
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=1059522&r1=1059521&r2=1059522&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderRollingFile.php
(original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderRollingFile.php
Sun Jan 16 09:29:43 2011
@@ -21,18 +21,18 @@
/**
* LoggerAppenderRollingFile extends LoggerAppenderFile to backup the log
files
* when they reach a certain size.
+ *
+ * This appender uses a layout.
*
* Parameters are:
- *
- * - 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)
*
* <p>Contributors: Sergio Strampelli.</p>
*
@@ -145,8 +145,8 @@ class LoggerAppenderRollingFile extends
$this->setFile($fileName, false);
}
- public function setFileName($fileName) {
- $this->fileName = $fileName;
+ public function setFile($fileName) {
+ $this->file = $fileName;
// 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));
@@ -187,7 +187,7 @@ class LoggerAppenderRollingFile extends
/**
* Set the maximum size that the output file is allowed to reach
* before being rolled over to backup files.
- * <p>In configuration files, the <b>MaxFileSize</b> option takes an
+ * <p>In configuration files, the <b>maxFileSize</b> 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
@@ -223,8 +223,34 @@ class LoggerAppenderRollingFile extends
*/
public function append(LoggerLoggingEvent $event) {
parent::append($event);
- if(ftell($this->fp) > $this->getMaximumFileSize()) {
+ if(ftell($this->fp) > $this->getMaxFileSize()) {
$this->rollOver();
}
}
+
+
+ /**
+ * @return Returns the maximum number of backup files to keep around.
+ */
+ public function getMaxBackupIndex() {
+ return $this->maxBackupIndex;
+ }
+
+ /**
+ * @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->getMaxFileSize();
+ }
+
+
+ /**
+ * @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;
+ }
}
Modified:
logging/log4php/trunk/src/test/php/appenders/LoggerAppenderFileTest.php
URL:
http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/appenders/LoggerAppenderFileTest.php?rev=1059522&r1=1059521&r2=1059522&view=diff
==============================================================================
--- logging/log4php/trunk/src/test/php/appenders/LoggerAppenderFileTest.php
(original)
+++ logging/log4php/trunk/src/test/php/appenders/LoggerAppenderFileTest.php Sun
Jan 16 09:29:43 2011
@@ -40,7 +40,7 @@ class LoggerAppenderFileTest extends PHP
"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);
Modified:
logging/log4php/trunk/src/test/php/appenders/LoggerAppenderRollingFileTest.php
URL:
http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/appenders/LoggerAppenderRollingFileTest.php?rev=1059522&r1=1059521&r2=1059522&view=diff
==============================================================================
---
logging/log4php/trunk/src/test/php/appenders/LoggerAppenderRollingFileTest.php
(original)
+++
logging/log4php/trunk/src/test/php/appenders/LoggerAppenderRollingFileTest.php
Sun Jan 16 09:29:43 2011
@@ -74,7 +74,7 @@ class LoggerAppenderRollingFileTest exte
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,7 +85,7 @@ class LoggerAppenderRollingFileTest exte
$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->setMaxFileSize('1KB');
$appender->setMaxBackupIndex(2);