mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-06 05:07:36 +02:00
Remove Logstash V0 support
This commit is contained in:
@@ -21,9 +21,6 @@ namespace Monolog\Formatter;
|
||||
*/
|
||||
class LogstashFormatter extends NormalizerFormatter
|
||||
{
|
||||
const V0 = 0;
|
||||
const V1 = 1;
|
||||
|
||||
/**
|
||||
* @var string the name of the system for the Logstash log message, used to fill the @source field
|
||||
*/
|
||||
@@ -44,11 +41,6 @@ class LogstashFormatter extends NormalizerFormatter
|
||||
*/
|
||||
protected $contextPrefix;
|
||||
|
||||
/**
|
||||
* @var int logstash format version to use
|
||||
*/
|
||||
protected $version;
|
||||
|
||||
/**
|
||||
* @param string $applicationName the application that sends the data, used as the "type" field of logstash
|
||||
* @param string $systemName the system/machine name, used as the "source" field of logstash, defaults to the hostname of the machine
|
||||
@@ -56,7 +48,7 @@ class LogstashFormatter extends NormalizerFormatter
|
||||
* @param string $contextPrefix prefix for context keys inside logstash "fields", defaults to ctxt_
|
||||
* @param int $version the logstash format version to use, defaults to 0
|
||||
*/
|
||||
public function __construct($applicationName, $systemName = null, $extraPrefix = null, $contextPrefix = 'ctxt_', $version = self::V0)
|
||||
public function __construct($applicationName, $systemName = null, $extraPrefix = null, $contextPrefix = 'ctxt_')
|
||||
{
|
||||
// logstash requires a ISO 8601 format date with optional millisecond precision.
|
||||
parent::__construct('Y-m-d\TH:i:s.uP');
|
||||
@@ -65,7 +57,6 @@ class LogstashFormatter extends NormalizerFormatter
|
||||
$this->applicationName = $applicationName;
|
||||
$this->extraPrefix = $extraPrefix;
|
||||
$this->contextPrefix = $contextPrefix;
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,60 +66,6 @@ class LogstashFormatter extends NormalizerFormatter
|
||||
{
|
||||
$record = parent::format($record);
|
||||
|
||||
if ($this->version === self::V1) {
|
||||
$message = $this->formatV1($record);
|
||||
} else {
|
||||
$message = $this->formatV0($record);
|
||||
}
|
||||
|
||||
return $this->toJson($message) . "\n";
|
||||
}
|
||||
|
||||
protected function formatV0(array $record)
|
||||
{
|
||||
if (empty($record['datetime'])) {
|
||||
$record['datetime'] = gmdate('c');
|
||||
}
|
||||
$message = array(
|
||||
'@timestamp' => $record['datetime'],
|
||||
'@source' => $this->systemName,
|
||||
'@fields' => array(),
|
||||
);
|
||||
if (isset($record['message'])) {
|
||||
$message['@message'] = $record['message'];
|
||||
}
|
||||
if (isset($record['channel'])) {
|
||||
$message['@tags'] = array($record['channel']);
|
||||
$message['@fields']['channel'] = $record['channel'];
|
||||
}
|
||||
if (isset($record['level'])) {
|
||||
$message['@fields']['level'] = $record['level'];
|
||||
}
|
||||
if ($this->applicationName) {
|
||||
$message['@type'] = $this->applicationName;
|
||||
}
|
||||
if (isset($record['extra']['server'])) {
|
||||
$message['@source_host'] = $record['extra']['server'];
|
||||
}
|
||||
if (isset($record['extra']['url'])) {
|
||||
$message['@source_path'] = $record['extra']['url'];
|
||||
}
|
||||
if (!empty($record['extra'])) {
|
||||
foreach ($record['extra'] as $key => $val) {
|
||||
$message['@fields'][$this->extraPrefix . $key] = $val;
|
||||
}
|
||||
}
|
||||
if (!empty($record['context'])) {
|
||||
foreach ($record['context'] as $key => $val) {
|
||||
$message['@fields'][$this->contextPrefix . $key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
protected function formatV1(array $record)
|
||||
{
|
||||
if (empty($record['datetime'])) {
|
||||
$record['datetime'] = gmdate('c');
|
||||
}
|
||||
@@ -161,6 +98,6 @@ class LogstashFormatter extends NormalizerFormatter
|
||||
}
|
||||
}
|
||||
|
||||
return $message;
|
||||
return $this->toJson($message) . "\n";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user