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

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

This commit is contained in:
Matthias Pigulla
2013-10-10 10:04:29 +02:00
parent 16f05a17e3
commit 540afb4621
2 changed files with 17 additions and 1 deletions

View File

@@ -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;
}
}

View File

@@ -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
*/