Author: dr
Date: Tue Feb  5 16:57:55 2008
New Revision: 7297

Log:
- Implemented feature #12503: Ability to disable log rotation by setting the
  max log file option to the constructor to false.

Modified:
    trunk/EventLog/ChangeLog
    trunk/EventLog/src/writers/writer_file.php
    trunk/EventLog/tests/writers/writer_file_test.php

Modified: trunk/EventLog/ChangeLog
==============================================================================
--- trunk/EventLog/ChangeLog [iso-8859-1] (original)
+++ trunk/EventLog/ChangeLog [iso-8859-1] Tue Feb  5 16:57:55 2008
@@ -1,3 +1,10 @@
+1.3alpha1 - [RELEASEDATE]
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Implemented feature #12503: Ability to disable log rotation by setting the
+  max log file option to the constructor to false.
+
+
 1.2 - Monday 17 December 2007
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 

Modified: trunk/EventLog/src/writers/writer_file.php
==============================================================================
--- trunk/EventLog/src/writers/writer_file.php [iso-8859-1] (original)
+++ trunk/EventLog/src/writers/writer_file.php [iso-8859-1] Tue Feb  5 16:57:55 
2008
@@ -13,10 +13,11 @@
  * system.
  *
  * The main purpose is to keep track of the various log files and support 
- * log rotation. The file format of the log should be implemented in a 
subclass.
+ * log rotation, although log rotation can also be disabled. The file format of
+ * the log should be implemented in a subclass.
  * 
- * The following example implements a new log writer that writes the output in 
([EMAIL PROTECTED] print_r()} format) 
- * to a file:
+ * The following example implements a new log writer that writes the output in
+ * ([EMAIL PROTECTED] print_r()} format) to a file:
  * <code>
  * class MyLogWriter extends ezcLogFileWriter
  * {
@@ -67,7 +68,8 @@
     protected $logDirectory;
 
     /**
-     * Maximum file size before rotation.
+     * Maximum file size before rotation, or false when log rotation is 
disabled.
+     *
      *
      * @var int
      */
@@ -91,12 +93,12 @@
      * If the file $defaultFile is not null, log messages that are not [EMAIL 
PROTECTED] map() mapped}
      * to any file are written to this $defaultFile. If $defaultFile is null, 
then
      * log messages are discarded.
-
      *
      * Set $maxLogRotationSize to specify the maximum size of a logfile. When 
the
      * maximum size is reached, the log will be rotated. $maxLogFiles sets the 
maximum 
      * number of rotated log files. The oldest rotated log will be removed 
when the
-     * maxLogFiles exceeds.
+     * $maxLogFiles exceeds. Log rotation can be disabled by setting
+     * $maxLogRotationSize to false.
      *
      * @param string $logDirectory
      * @param string $defaultFile
@@ -184,15 +186,14 @@
      */
     protected function openFile( $fileName )
     {
-        if ( isset( $this->openFiles[$fileName] ) )
-        {
-            return $this->openFiles[$fileName];
+        $path = $this->logDirectory . "/". $fileName;
+        if ( isset( $this->openFiles[$path] ) )
+        {
+            return $this->openFiles[$path];
         }
 
         clearstatcache();
-        $path = $this->logDirectory . "/". $fileName;
-        if ( file_exists( $path ) &&
-            ( filesize( $path ) >= $this->maxSize ) )
+        if ( $this->maxSize !== false && file_exists( $path ) && ( filesize( 
$path ) >= $this->maxSize ) )
         {
             $this->rotateLog( $fileName );
         }

Modified: trunk/EventLog/tests/writers/writer_file_test.php
==============================================================================
--- trunk/EventLog/tests/writers/writer_file_test.php [iso-8859-1] (original)
+++ trunk/EventLog/tests/writers/writer_file_test.php [iso-8859-1] Tue Feb  5 
16:57:55 2008
@@ -154,6 +154,24 @@
         $this->assertEquals(print_r($msg, true), file_get_contents( 
$this->getTempDir() . "/default.log.1") );
     }
 
+    public function testLogRotateDisabled()
+    {
+        $msg = array("message" => "1234567890123456789012345",
+                     "type" => 1,
+                     "source" => "s",
+                     "category" => "c");
+
+        for ( $i = 0; $i < 50000; $i++ )
+        {
+            $this->writer = new TempImplementation($this->getTempDir(), 
$this->logFile, false);
+
+            $this->writer->writeLogMessage( $msg["message"], $msg["type"], 
$msg["source"], $msg["category"]);
+            clearstatcache();
+        }
+        $this->assertTrue(file_exists( $this->getTempDir() ."/default.log"), 
"Log rotation messes up the default log file." );
+        $this->assertFalse(file_exists( $this->getTempDir() 
."/default.log.1"), "Expected that the log files don't rotate." );
+    }
+
     public function testMaxLogFiles()
     {
         $msg = array("message" => "1234567890",


-- 
svn-components mailing list
svn-components@lists.ez.no
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to