Ludovic Chabant avatar Ludovic Chabant committed d0b4831

Added support for buffering in the PearLog.

Comments (0)

Files changed (1)

lib/StupidHttp/PearLog.php

         return new StupidHttp_PearLog($logger);
     }
 
+    protected $isBuffering;
+    protected $bufferedMessages;
+
     protected $log;
     /**
      * Creates a new instance of StupidHttp_PearLog wrapped around the given PEAR logger.
     public function __construct(Log $log)
     {
         $this->log = $log;
+        $this->isBuffering = false;
+        $this->bufferedMessages = array();
     }
     
     /**
             $pearType = PEAR_LOG_DEBUG;
             break;
         }
-        $this->log->log($message, $pearType);
+        if ($this->isBuffering)
+        {
+            $this->bufferedMessages[] = array(
+                'message' => $message,
+                'type' => $pearType
+            );
+        }
+        else
+        {
+            $this->log->log($message, $pearType);
+        }
+    }
+
+    public function _startBuffering()
+    {
+        $this->isBuffering = true;
+    }
+
+    public function _endBuffering()
+    {
+        foreach ($this->bufferedMessages as $m)
+        {
+            $this->log->log($m['message'], $m['type']);
+        }
+        $this->bufferedMessages = array();
+        $this->isBuffering = false;
     }
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.