Просмотр исходного кода

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

Jordi Boggiano 12 лет назад
Родитель
Сommit
df1f411378
2 измененных файлов с 25 добавлено и 19 удалено
  1. 1 1
      src/Monolog/Handler/CubeHandler.php
  2. 24 18
      src/Monolog/Handler/NewRelicHandler.php

+ 1 - 1
src/Monolog/Handler/CubeHandler.php

@@ -64,7 +64,7 @@ class CubeHandler extends AbstractProcessingHandler
     protected function connectUdp()
     {
         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);

+ 24 - 18
src/Monolog/Handler/NewRelicHandler.php

@@ -11,43 +11,49 @@
 
 namespace Monolog\Handler;
 
-use Monolog\Handler\MissingExtensionException;
-
 /**
  * Class to record a log on a NewRelic application
  *
  * @see https://newrelic.com/docs/php/new-relic-for-php
  */
 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)
     {
-        if ($this->isNewRelicEnabled()) {
+        if (!$this->isNewRelicEnabled()) {
+            throw new MissingExtensionException('The newrelic PHP extension is required to use the NewRelicHandler');
+        }
+
+        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);
-            }
-            
-            return;
+        foreach ($record['context'] as $key => $parameter) {
+            newrelic_add_custom_parameter($key, $parameter);
         }
-        
-        throw new MissingExtensionException(self::ERROR_MISSING_EXTENSION);
     }
-    
+
     /**
      * Checks whether the NewRelic extension is enabled in the system.
-     * 
+     *
      * @return bool
      */
     protected function isNewRelicEnabled()
     {
-        return (bool) extension_loaded(self::NEWRELIC_EXTENSION_NAME);
+        return extension_loaded('newrelic');
     }
 }