1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-01 10:50:21 +02:00

Logmatic fix (#914)

* Adding the marker field to improve the Logmatic.io compatibilty
This commit is contained in:
Guillaume Polaert
2017-03-12 17:13:04 +01:00
committed by Jordi Boggiano
parent c7776bba2b
commit 908960d30b
3 changed files with 12 additions and 7 deletions

View File

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

View File

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

View File

@@ -37,7 +37,7 @@ class LogmaticHandlerTest extends TestCase
fseek($this->res, 0); fseek($this->res, 0);
$content = fread($this->res, 1024); $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() public function testWriteBatchContent()
@@ -53,7 +53,7 @@ class LogmaticHandlerTest extends TestCase
fseek($this->res, 0); fseek($this->res, 0);
$content = fread($this->res, 1024); $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() private function createHandler()