Bläddra i källkod

Simplify code and cache the getmypid call, refs #167

Jordi Boggiano 13 år sedan
förälder
incheckning
047488810f

+ 10 - 8
src/Monolog/Processor/ProcessIdProcessor.php

@@ -18,20 +18,22 @@ namespace Monolog\Processor;
  */
 class ProcessIdProcessor
 {
+    private static $pid;
+
+    public function __construct()
+    {
+        if (null === self::$pid) {
+            self::$pid = getmypid();
+        }
+    }
+
     /**
      * @param  array $record
      * @return array
      */
     public function __invoke(array $record)
     {
-        $pid = getmypid();
-
-        $record['extra'] = array_merge(
-            $record['extra'],
-            array(
-                'process_id' => $pid,
-            )
-        );
+        $record['extra']['process_id'] = self::$pid;
 
         return $record;
     }

+ 1 - 0
tests/Monolog/Processor/ProcessIdProcessorTest.php

@@ -25,5 +25,6 @@ class ProcessIdProcessorTest extends TestCase
         $this->assertArrayHasKey('process_id', $record['extra']);
         $this->assertInternalType('int', $record['extra']['process_id']);
         $this->assertGreaterThan(0, $record['extra']['process_id']);
+        $this->assertEquals(getmypid(), $record['extra']['process_id']);
     }
 }