mirror of
https://github.com/Seldaek/monolog.git
synced 2025-07-30 18:00:17 +02:00
Logmatic fix (#914)
* Adding the marker field to improve the Logmatic.io compatibilty
This commit is contained in:
committed by
Jordi Boggiano
parent
c7776bba2b
commit
908960d30b
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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.
|
||||
|
@@ -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()
|
||||
|
Reference in New Issue
Block a user