瀏覽代碼

Logmatic fix (#914)

* Adding the marker field to improve the Logmatic.io compatibilty
Guillaume Polaert 8 年之前
父節點
當前提交
908960d30b

+ 7 - 2
src/Monolog/Formatter/LogmaticFormatter.php

@@ -18,6 +18,9 @@ namespace Monolog\Formatter;
  */
 class LogmaticFormatter extends JsonFormatter
 {
+
+    const MARKERS = ["sourcecode", "php"];
+
     /**
      * @param string
      */
@@ -57,12 +60,14 @@ class LogmaticFormatter extends JsonFormatter
     public function format(array $record): string
     {
         if (!empty($this->hostname)) {
-            $record['hostname'] = $this->hostname;
+            $record["hostname"] = $this->hostname;
         }
         if (!empty($this->appname)) {
-            $record['appname'] = $this->appname;
+            $record["appname"] = $this->appname;
         }
 
+        $record["@marker"] = self::MARKERS;
+
         return parent::format($record);
     }
 }

+ 3 - 3
src/Monolog/Handler/LogmaticHandler.php

@@ -23,17 +23,17 @@ class LogmaticHandler extends SocketHandler
     /**
      * @var string
      */
-    protected $logToken;
+    private $logToken;
 
     /**
      * @var string
      */
-    protected $hostname;
+    private $hostname;
 
     /**
      * @var string
      */
-    protected $appname;
+    private $appname;
 
     /**
      * @param string     $token    Log token supplied by Logmatic.

+ 2 - 2
tests/Monolog/Handler/LogmaticHandlerTest.php

@@ -37,7 +37,7 @@ class LogmaticHandlerTest extends TestCase
         fseek($this->res, 0);
         $content = fread($this->res, 1024);
 
-        $this->assertRegexp('/testToken {"message":"Critical write test","context":\[\],"level":500,"level_name":"CRITICAL","channel":"test","datetime":"(.*)","extra":\[\],"hostname":"testHostname","appname":"testAppname"}/', $content);
+        $this->assertRegexp('/testToken {"message":"Critical write test","context":\[\],"level":500,"level_name":"CRITICAL","channel":"test","datetime":"(.*)","extra":\[\],"hostname":"testHostname","appname":"testAppname","@marker":\["sourcecode","php"\]}/', $content);
     }
 
     public function testWriteBatchContent()
@@ -53,7 +53,7 @@ class LogmaticHandlerTest extends TestCase
         fseek($this->res, 0);
         $content = fread($this->res, 1024);
 
-        $this->assertRegexp('/testToken {"message":"test","context":\[\],"level":300,"level_name":"WARNING","channel":"test","datetime":"(.*)","extra":\[\],"hostname":"testHostname","appname":"testAppname"}/', $content);
+        $this->assertRegexp('/testToken {"message":"test","context":\[\],"level":300,"level_name":"WARNING","channel":"test","datetime":"(.*)","extra":\[\],"hostname":"testHostname","appname":"testAppname","@marker":\["sourcecode","php"\]}/', $content);
     }
 
     private function createHandler()