Sfoglia il codice sorgente

Add unique_id to extra data only if present in the server environment

Matthias Pigulla 12 anni fa
parent
commit
540afb4621

+ 4 - 1
src/Monolog/Processor/WebProcessor.php

@@ -54,10 +54,13 @@ class WebProcessor
                 'http_method' => isset($this->serverData['REQUEST_METHOD']) ? $this->serverData['REQUEST_METHOD'] : null,
                 'server'      => isset($this->serverData['SERVER_NAME']) ? $this->serverData['SERVER_NAME'] : null,
                 'referrer'    => isset($this->serverData['HTTP_REFERER']) ? $this->serverData['HTTP_REFERER'] : null,
-                'unique_id'   => isset($this->serverData['UNIQUE_ID']) ? $this->serverData['UNIQUE_ID'] : null,
             )
         );
 
+        if (isset($this->serverData['UNIQUE_ID'])) {
+            $record['extra']['unique_id'] = $this->serverData['UNIQUE_ID'];
+        }
+
         return $record;
     }
 }

+ 13 - 0
tests/Monolog/Processor/WebProcessorTest.php

@@ -60,6 +60,19 @@ class WebProcessorTest extends TestCase
         $this->assertNull($record['extra']['referrer']);
     }
 
+    public function testProcessorDoesNotAddUniqueIdIfNotPresent()
+    {
+        $server = array(
+            'REQUEST_URI'    => 'A',
+            'REMOTE_ADDR'    => 'B',
+            'REQUEST_METHOD' => 'C',
+            'SERVER_NAME'    => 'F',
+        );
+        $processor = new WebProcessor($server);
+        $record = $processor($this->getRecord());
+        $this->assertFalse(isset($record['extra']['unique_id']));
+    }
+
     /**
      * @expectedException UnexpectedValueException
      */