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

Merge pull request #515 from smazurov/patch-1

Added overwriting of user context to RavenHandler
This commit is contained in:
Jordi Boggiano
2015-02-28 21:21:16 +00:00
2 changed files with 26 additions and 0 deletions

View File

@@ -127,6 +127,8 @@ class RavenHandler extends AbstractProcessingHandler
*/
protected function write(array $record)
{
// ensures user context is empty
$this->ravenClient->user_context(null);
$options = array();
$options['level'] = $this->logLevels[$record['level']];
$options['tags'] = array();
@@ -146,6 +148,10 @@ class RavenHandler extends AbstractProcessingHandler
}
if (!empty($record['context'])) {
$options['extra']['context'] = $record['context'];
if (!empty($record['context']['user'])) {
$this->ravenClient->user_context($record['context']['user']);
unset($options['extra']['context']['user']);
}
}
if (!empty($record['extra'])) {
$options['extra']['extra'] = $record['extra'];

View File

@@ -85,6 +85,26 @@ class RavenHandlerTest extends TestCase
$this->assertEquals($tags, $ravenClient->lastData['tags']);
}
public function testUserContext()
{
$ravenClient = $this->getRavenClient();
$handler = $this->getHandler($ravenClient);
$user = array(
'id' => '123',
'email' => 'test@test.com'
);
$record = $this->getRecord(Logger::INFO, "test", array('user' => $user));
$handler->handle($record);
$this->assertEquals($user, $ravenClient->context->user);
$secondRecord = $this->getRecord(Logger::INFO, "test without user");
$handler->handle($secondRecord);
$this->assertNull($ravenClient->context->user);
}
public function testException()
{
$ravenClient = $this->getRavenClient();