Skip to content

Commit

Permalink
Add more testing for extra context data
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed May 9, 2015
1 parent 6b22591 commit c509ad8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
14 changes: 9 additions & 5 deletions src/RavenLogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,14 @@ protected function addContext(array $context = [])
$context['tags'] = $tags;
}

// Automatic extra data.
$extra = [
'ip' => $this->app->request->getClientIp(),
];

// Everything that is not 'user', 'tags' or 'level' is automatically considered
// as additonal 'extra' context data.
$extra = array_except($context, ['user', 'tags', 'level']);
$context = array_only($context, ['user', 'tags', 'level']);

// Automatic extra data.
$extra['ip'] = $this->app->request->getClientIp();
$extra = array_merge($extra, array_except($context, ['user', 'tags', 'level', 'extra']));

// Add extra to context.
if (isset($context['extra']))
Expand All @@ -133,6 +134,9 @@ protected function addContext(array $context = [])
$context['extra'] = $extra;
}

// Clean out other values from context.
$context = array_only($context, ['user', 'tags', 'level', 'extra']);

return $context;
}

Expand Down
13 changes: 10 additions & 3 deletions tests/RavenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ public function testEasyExtraData()
'server' => 'localhost',
],
'extra' => [
'ip' => '127.0.0.1',
'download_size' => 3432425235
'ip' => '192.168.0.1',
'download_size' => 3432425235,
'foo' => 'bar'
]
]);

Expand All @@ -154,7 +155,13 @@ public function testEasyExtraData()
$this->app['raven.handler'] = $handlerMock;

$handler = $this->app->make('raven.handler');
$handler->log('info', 'Test log message', ['download_size' => 3432425235]);
$handler->log('info', 'Test log message', [
'download_size' => 3432425235,
'ip' => '192.168.0.1',
'extra' => [
'foo' => 'bar'
]
]);
}

public function testLogListener()
Expand Down

0 comments on commit c509ad8

Please sign in to comment.