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

CS fixes and set the default NewRelicHandler level to ERROR, refs #105

This commit is contained in:
Jordi Boggiano
2013-07-28 23:10:25 +02:00
parent 043aabcf2f
commit df1f411378
2 changed files with 27 additions and 21 deletions

View File

@@ -64,7 +64,7 @@ class CubeHandler extends AbstractProcessingHandler
protected function connectUdp() protected function connectUdp()
{ {
if (!extension_loaded('sockets')) { if (!extension_loaded('sockets')) {
throw new \LogicException('The sockets extension is needed to use udp URLs with the CubeHandler'); throw new MissingExtensionException('The sockets extension is required to use udp URLs with the CubeHandler');
} }
$this->udpConnection = socket_create(AF_INET, SOCK_DGRAM, 0); $this->udpConnection = socket_create(AF_INET, SOCK_DGRAM, 0);

View File

@@ -11,8 +11,6 @@
namespace Monolog\Handler; namespace Monolog\Handler;
use Monolog\Handler\MissingExtensionException;
/** /**
* Class to record a log on a NewRelic application * Class to record a log on a NewRelic application
* *
@@ -20,25 +18,33 @@ use Monolog\Handler\MissingExtensionException;
*/ */
class NewRelicHandler extends AbstractProcessingHandler class NewRelicHandler extends AbstractProcessingHandler
{ {
const ERROR_MISSING_EXTENSION = "The NewRelic PHP extension is not installed on this system, therefore you can't use the NewRelicHandler"; /**
const NEWRELIC_EXTENSION_NAME = 'newrelic'; * {@inheritDoc}
*/
public function __construct($level = Logger::ERROR, $bubble = true)
{
parent::__construct($level, $bubble);
}
/** /**
* {@inheritdoc} * {@inheritDoc}
*/ */
protected function write(array $record) protected function write(array $record)
{ {
if ($this->isNewRelicEnabled()) { if (!$this->isNewRelicEnabled()) {
newrelic_notice_error($record['message']); throw new MissingExtensionException('The newrelic PHP extension is required to use the NewRelicHandler');
foreach ($record['context'] as $key => $parameter) {
newrelic_add_custom_parameter($key, $parameter);
}
return;
} }
throw new MissingExtensionException(self::ERROR_MISSING_EXTENSION); if (isset($record['context']['exception']) && $record['context']['exception'] instanceof \Exception) {
newrelic_notice_error($record['message'], $record['context']['exception']);
unset($record['context']['exception']);
} else {
newrelic_notice_error($record['message']);
}
foreach ($record['context'] as $key => $parameter) {
newrelic_add_custom_parameter($key, $parameter);
}
} }
/** /**
@@ -48,6 +54,6 @@ class NewRelicHandler extends AbstractProcessingHandler
*/ */
protected function isNewRelicEnabled() protected function isNewRelicEnabled()
{ {
return (bool) extension_loaded(self::NEWRELIC_EXTENSION_NAME); return extension_loaded('newrelic');
} }
} }