1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-22 17:16:18 +02:00

Address a few of the concerns from @stof in #76.

This commit is contained in:
Marc Abramowitz
2012-10-24 23:48:18 -07:00
parent 4830b92725
commit 5d172122bc
2 changed files with 19 additions and 25 deletions

View File

@@ -21,28 +21,11 @@ use Raven_Client;
*/ */
class RavenFormatter extends NormalizerFormatter class RavenFormatter extends NormalizerFormatter
{ {
/**
* Translates Monolog log levels to Raven log levels.
*/
private $logLevels = array(
Logger::DEBUG => Raven_Client::DEBUG,
Logger::INFO => Raven_Client::INFO,
Logger::WARNING => Raven_Client::WARNING,
Logger::ERROR => Raven_Client::ERROR,
Logger::CRITICAL => Raven_Client::ERROR,
Logger::ALERT => Raven_Client::ERROR,
);
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function format(array $record) public function format(array $record)
{ {
$record = parent::format($record); return $record['channel'] . ': ' . $record['message'];
$record['level'] = $this->logLevels[$record['level']];
$record['message'] = $record['channel'] . ': ' . $record['message'];
return $record;
} }
} }

View File

@@ -24,6 +24,18 @@ use \Raven_Client;
*/ */
class RavenHandler extends AbstractProcessingHandler class RavenHandler extends AbstractProcessingHandler
{ {
/**
* Translates Monolog log levels to Raven log levels.
*/
private $logLevels = array(
Logger::DEBUG => Raven_Client::DEBUG,
Logger::INFO => Raven_Client::INFO,
Logger::WARNING => Raven_Client::WARNING,
Logger::ERROR => Raven_Client::ERROR,
Logger::CRITICAL => Raven_Client::ERROR,
Logger::ALERT => Raven_Client::ERROR,
);
/** /**
* @var Raven_Client the client object that sends the message to the server * @var Raven_Client the client object that sends the message to the server
*/ */
@@ -54,15 +66,14 @@ class RavenHandler extends AbstractProcessingHandler
*/ */
protected function write(array $record) protected function write(array $record)
{ {
$this->ravenClient->captureMessage(
$record['formatted'],
$record['formatted'], // $params
$this->logLevels[$record['level']], // $level
false // $stack
);
if ($record['level'] >= Logger::ERROR && isset($record['context']['exception'])) { if ($record['level'] >= Logger::ERROR && isset($record['context']['exception'])) {
$this->ravenClient->captureException($record['context']['exception']); $this->ravenClient->captureException($record['context']['exception']);
} else {
$this->ravenClient->captureMessage(
$record['formatted']['message'],
$record, // $params
$record['formatted']['level'], // $level
true // $stack
);
} }
} }