Ver código fonte

Changing the SocketHandler to call generateDataStream when writing to socket

Now the write method does not to be overwritten when the format of the dataStream the Socket sends has to be altered in any way the formatter cannot handle (See the PushoverHandler for an example)
Sebastian Goettschkes 13 anos atrás
pai
commit
f2bac1f351
1 arquivos alterados com 7 adições e 1 exclusões
  1. 7 1
      src/Monolog/Handler/SocketHandler.php

+ 7 - 1
src/Monolog/Handler/SocketHandler.php

@@ -53,7 +53,8 @@ class SocketHandler extends AbstractProcessingHandler
     public function write(array $record)
     {
         $this->connectIfNotConnected();
-        $this->writeToSocket((string) $record['formatted']);
+        $data = $this->generateDataStream($record);
+        $this->writeToSocket($data);
     }
 
     /**
@@ -227,6 +228,11 @@ class SocketHandler extends AbstractProcessingHandler
         $this->connect();
     }
 
+    protected function generateDataStream($record)
+    {
+        return (string) $record['formatted'];
+    }
+
     private function connect()
     {
         $this->createSocketResource();