1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-25 02:26:16 +02:00

Merge branch 'master' into feature/elasticsearch

This commit is contained in:
Avtandil Kikabidze
2018-09-12 18:08:44 +04:00
78 changed files with 268 additions and 349 deletions

View File

@@ -58,13 +58,13 @@ class GelfMessageFormatter extends NormalizerFormatter
Logger::EMERGENCY => 0,
];
public function __construct(string $systemName = null, string $extraPrefix = null, string $contextPrefix = 'ctxt_', int $maxLength = null)
public function __construct(?string $systemName = null, ?string $extraPrefix = null, string $contextPrefix = 'ctxt_', ?int $maxLength = null)
{
parent::__construct('U.u');
$this->systemName = $systemName ?: gethostname();
$this->systemName = (is_null($systemName) || $systemName === '') ? gethostname() : $systemName;
$this->extraPrefix = $extraPrefix;
$this->extraPrefix = is_null($extraPrefix) ? '' : $extraPrefix;
$this->contextPrefix = $contextPrefix;
$this->maxLength = is_null($maxLength) ? self::DEFAULT_MAX_LENGTH : $maxLength;
}

View File

@@ -37,9 +37,9 @@ class HtmlFormatter extends NormalizerFormatter
];
/**
* @param string $dateFormat The format of the timestamp: one supported by DateTime::format
* @param ?string $dateFormat The format of the timestamp: one supported by DateTime::format
*/
public function __construct(string $dateFormat = null)
public function __construct(?string $dateFormat = null)
{
parent::__construct($dateFormat);
}
@@ -47,10 +47,9 @@ class HtmlFormatter extends NormalizerFormatter
/**
* Creates an HTML table row
*
* @param string $th Row header content
* @param string $td Row standard cell content
* @param bool $escapeTd false if td content must not be html escaped
* @return string
* @param string $th Row header content
* @param string $td Row standard cell content
* @param bool $escapeTd false if td content must not be html escaped
*/
protected function addRow(string $th, string $td = ' ', bool $escapeTd = true): string
{
@@ -79,8 +78,8 @@ class HtmlFormatter extends NormalizerFormatter
/**
* Formats a log record.
*
* @param array $record A record to format
* @return mixed The formatted record
* @param array $record A record to format
* @return string The formatted record
*/
public function format(array $record): string
{
@@ -113,8 +112,8 @@ class HtmlFormatter extends NormalizerFormatter
/**
* Formats a set of log records.
*
* @param array $records A set of records to format
* @return mixed The formatted set of records
* @param array $records A set of records to format
* @return string The formatted set of records
*/
public function formatBatch(array $records): string
{

View File

@@ -61,6 +61,8 @@ class JsonFormatter extends NormalizerFormatter
/**
* {@inheritdoc}
*
* @suppress PhanTypeComparisonToArray
*/
public function format(array $record): string
{

View File

@@ -29,14 +29,14 @@ class LineFormatter extends NormalizerFormatter
protected $includeStacktraces;
/**
* @param string $format The format of the message
* @param string $dateFormat The format of the timestamp: one supported by DateTime::format
* @param bool $allowInlineLineBreaks Whether to allow inline line breaks in log entries
* @param bool $ignoreEmptyContextAndExtra
* @param ?string $format The format of the message
* @param ?string $dateFormat The format of the timestamp: one supported by DateTime::format
* @param bool $allowInlineLineBreaks Whether to allow inline line breaks in log entries
* @param bool $ignoreEmptyContextAndExtra
*/
public function __construct(string $format = null, string $dateFormat = null, bool $allowInlineLineBreaks = false, bool $ignoreEmptyContextAndExtra = false)
public function __construct(?string $format = null, ?string $dateFormat = null, bool $allowInlineLineBreaks = false, bool $ignoreEmptyContextAndExtra = false)
{
$this->format = $format ?: static::SIMPLE_FORMAT;
$this->format = $format === null ? static::SIMPLE_FORMAT : $format;
$this->allowInlineLineBreaks = $allowInlineLineBreaks;
$this->ignoreEmptyContextAndExtra = $ignoreEmptyContextAndExtra;
parent::__construct($dateFormat);
@@ -124,6 +124,9 @@ class LineFormatter extends NormalizerFormatter
return $this->replaceNewlines($this->convertToString($value));
}
/**
* @suppress PhanParamSignatureMismatch
*/
protected function normalizeException(\Throwable $e, int $depth = 0): string
{
$str = $this->formatException($e);

View File

@@ -21,30 +21,20 @@ class LogmaticFormatter extends JsonFormatter
const MARKERS = ["sourcecode", "php"];
/**
* @param string
* @var string
*/
protected $hostname = '';
/**
* @param string
* @var string
*/
protected $appname = '';
/**
* Set hostname
*
* @param string $hostname
*/
public function setHostname(string $hostname)
{
$this->hostname = $hostname;
}
/**
* Set appname
*
* @param string $appname
*/
public function setAppname(string $appname)
{
$this->appname = $appname;

View File

@@ -42,17 +42,17 @@ class LogstashFormatter extends NormalizerFormatter
protected $contextKey;
/**
* @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
* @param string $extraKey the key for extra keys inside logstash "fields", defaults to extra
* @param string $contextKey the key for context keys inside logstash "fields", defaults to context
* @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
* @param string $extraKey the key for extra keys inside logstash "fields", defaults to extra
* @param string $contextKey the key for context keys inside logstash "fields", defaults to context
*/
public function __construct(string $applicationName, string $systemName = null, string $extraKey = 'extra', string $contextKey = 'context')
public function __construct(string $applicationName, ?string $systemName = null, string $extraKey = 'extra', string $contextKey = 'context')
{
// logstash requires a ISO 8601 format date with optional millisecond precision.
parent::__construct('Y-m-d\TH:i:s.uP');
$this->systemName = $systemName ?: gethostname();
$this->systemName = $systemName === null ? gethostname() : $systemName;
$this->applicationName = $applicationName;
$this->extraKey = $extraKey;
$this->contextKey = $contextKey;

View File

@@ -28,9 +28,9 @@ class NormalizerFormatter implements FormatterInterface
protected $maxNormalizeItemCount = 1000;
/**
* @param string $dateFormat The format of the timestamp: one supported by DateTime::format
* @param ?string $dateFormat The format of the timestamp: one supported by DateTime::format
*/
public function __construct(string $dateFormat = null)
public function __construct(?string $dateFormat = null)
{
$this->dateFormat = null === $dateFormat ? static::SIMPLE_DATE : $dateFormat;
if (!function_exists('json_encode')) {

View File

@@ -91,7 +91,7 @@ class WildfireFormatter extends NormalizerFormatter
// The message itself is a serialization of the above JSON object + it's length
return sprintf(
'%s|%s|',
'%d|%s|',
strlen($json),
$json
);
@@ -107,6 +107,7 @@ class WildfireFormatter extends NormalizerFormatter
/**
* {@inheritdoc}
* @suppress PhanTypeMismatchReturn
*/
protected function normalize($data, int $depth = 0)
{