1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-10 07:06:40 +02:00

Simplify code and cache the getmypid call, refs #167

This commit is contained in:
Jordi Boggiano
2013-02-21 10:08:33 +01:00
parent e4d521f8f2
commit 047488810f
2 changed files with 11 additions and 8 deletions

View File

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

View File

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