Author: Raymond Bosman
Date: 2006-01-25 10:11:57 +0100 (Wed, 25 Jan 2006)
New Revision: 2023

Log:
- Automatic attributes were not appended to the log.
# Included the test.

Modified:
   packages/EventLog/trunk/ChangeLog
   packages/EventLog/trunk/src/log.php
   packages/EventLog/trunk/tests/log_test.php

Modified: packages/EventLog/trunk/ChangeLog
===================================================================
--- packages/EventLog/trunk/ChangeLog   2006-01-24 22:07:27 UTC (rev 2022)
+++ packages/EventLog/trunk/ChangeLog   2006-01-25 09:11:57 UTC (rev 2023)
@@ -1,6 +1,7 @@
 1.0 - [RELEASEDATE]
 
 - Fixed bug #7706: ezcLogWriterFile truncates log files every request.
+- Fixed a problem that automatic attributes weren't appended to the log.
 
 
 1.0rc1 - Monday 16 January 2006

Modified: packages/EventLog/trunk/src/log.php
===================================================================
--- packages/EventLog/trunk/src/log.php 2006-01-24 22:07:27 UTC (rev 2022)
+++ packages/EventLog/trunk/src/log.php 2006-01-25 09:11:57 UTC (rev 2023)
@@ -16,7 +16,7 @@
  * - [EMAIL PROTECTED] ezcLogWriterUnixFile Unix File} writer
  * - [EMAIL PROTECTED] ezcLogWriterDatabase Database} writer
  *
- * Extra writers can be added by implementing the the [EMAIL PROTECTED] 
ezcLogWriter} interface.
+ * Extra writers can be added by implementing the [EMAIL PROTECTED] 
ezcLogWriter} interface.
  * 
  * Use the [EMAIL PROTECTED] getMapper()} method to get an instance of the 
ezcLogMapper.
  * The ezcLogMapper classes specifies incoming log messages with the [EMAIL 
PROTECTED] ezcLogFilter}.
@@ -415,6 +415,8 @@
         unset( $attributes["source"] );
         unset( $attributes["category"] );
 
+        $attributes = array_merge( $this->context->getContext( $severity, 
$source ), $attributes );
+
         $writers = $this->writers->get( $severity, $source, $category );
         foreach ( $writers as $writer )
         {

Modified: packages/EventLog/trunk/tests/log_test.php
===================================================================
--- packages/EventLog/trunk/tests/log_test.php  2006-01-24 22:07:27 UTC (rev 
2022)
+++ packages/EventLog/trunk/tests/log_test.php  2006-01-25 09:11:57 UTC (rev 
2023)
@@ -399,6 +399,7 @@
         $db->exec("DROP TABLE `audits`");
     }
 
+    */
 
     public function testDefaultProperties()
     {
@@ -408,7 +409,7 @@
 
         $dir = $this->getTempDir();
         $file = "default.log";
-        $this->log->map( new ezcLogFilter, $writer = new ezcLogWriterUnixFile( 
$dir, $file ) );
+        $this->log->getMapper()->appendRule( new ezcLogFilterRule(  new 
ezcLogFilter, $writer = new ezcLogWriterUnixFile( $dir, $file ), true ) );
 
         $this->log->log("Error", ezcLog::ERROR );
 
@@ -419,9 +420,43 @@
         $this->assertTrue( strstr( $str,  "MyCategory" ) !== false );
     }
     
-    */
+    public function testAutoAttributes()
+    {
+        $dir = $this->getTempDir();
+        $file = "default.log";
 
+        $log = ezcLog::getInstance();
+        $writer = new ezcLogWriterUnixFile( "$dir", "$file" );
+        $log->getmapper()->appendRule( new ezcLogFilterRule( new ezcLogFilter, 
$writer, true ) );
 
+        $username = "John Doe";
+        $service = "Paynet Terminal";
+
+        // Add automatically the username to the log message, when the log 
message is either a SUCCESS_AUDIT or a FAILED_AUDIT.
+        $log->setSeverityAttributes( ezcLog::SUCCESS_AUDIT | 
ezcLog::FAILED_AUDIT, array( "username" => $username ) );
+
+        // Same can be done with the source of the log message.
+        $log->setSourceAttributes( array( "Payment" ), array( "service" => 
$service ) );
+
+        // Writing some log messages.
+        $log->log( "Authentication failed", ezcLog::FAILED_AUDIT, array( 
"source" => "security", "category" => "login/logoff" ) );
+
+        $log->source = "Payment"; 
+        $log->log( "Connecting with the server.", ezcLog::DEBUG, array( 
"category" => "external connections" ) );
+
+        $log->log( "Payed with creditcard.", ezcLog::SUCCESS_AUDIT, array( 
"category" => "shop" ) );
+
+        $lines = file( "$dir/$file" );
+
+        $this->assertRegExp("/username: John Doe/", $lines[0]);
+
+        $this->assertRegExp("/service: Paynet Terminal/", $lines[1]);
+
+        $this->assertRegExp("/username: John Doe/", $lines[2]);
+        $this->assertRegExp("/service: Paynet Terminal/", $lines[2]);
+    }
+
+
     public static function suite()
     {
          return new ezcTestSuite("ezcLogTest");

-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to