1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-19 23:56:17 +02:00

Add scalar types to processor/formatters and top level classes

This commit is contained in:
Jordi Boggiano
2016-09-25 21:23:35 +02:00
parent 760dc44ebd
commit 6e6586257d
29 changed files with 130 additions and 196 deletions

View File

@@ -27,16 +27,16 @@ class MongoDBFormatter implements FormatterInterface
* @param int $maxNestingLevel 0 means infinite nesting, the $record itself is level 1, $record['context'] is 2
* @param bool $exceptionTraceAsString set to false to log exception traces as a sub documents instead of strings
*/
public function __construct($maxNestingLevel = 3, $exceptionTraceAsString = true)
public function __construct(int $maxNestingLevel = 3, bool $exceptionTraceAsString = true)
{
$this->maxNestingLevel = max($maxNestingLevel, 0);
$this->exceptionTraceAsString = (bool) $exceptionTraceAsString;
$this->exceptionTraceAsString = $exceptionTraceAsString;
}
/**
* {@inheritDoc}
*/
public function format(array $record)
public function format(array $record): array
{
return $this->formatArray($record);
}
@@ -44,7 +44,7 @@ class MongoDBFormatter implements FormatterInterface
/**
* {@inheritDoc}
*/
public function formatBatch(array $records)
public function formatBatch(array $records): array
{
foreach ($records as $key => $record) {
$records[$key] = $this->format($record);
@@ -53,7 +53,10 @@ class MongoDBFormatter implements FormatterInterface
return $records;
}
protected function formatArray(array $record, $nestingLevel = 0)
/**
* @return array|string Array except when max nesting level is reached then a string "[...]"
*/
protected function formatArray(array $record, int $nestingLevel = 0)
{
if ($this->maxNestingLevel == 0 || $nestingLevel <= $this->maxNestingLevel) {
foreach ($record as $name => $value) {
@@ -74,7 +77,7 @@ class MongoDBFormatter implements FormatterInterface
return $record;
}
protected function formatObject($value, $nestingLevel)
protected function formatObject($value, int $nestingLevel)
{
$objectVars = get_object_vars($value);
$objectVars['class'] = get_class($value);
@@ -82,7 +85,7 @@ class MongoDBFormatter implements FormatterInterface
return $this->formatArray($objectVars, $nestingLevel);
}
protected function formatException(\Throwable $exception, $nestingLevel)
protected function formatException(\Throwable $exception, int $nestingLevel)
{
$formattedException = [
'class' => get_class($exception),
@@ -100,7 +103,7 @@ class MongoDBFormatter implements FormatterInterface
return $this->formatArray($formattedException, $nestingLevel);
}
protected function formatDate(\DateTimeInterface $value, $nestingLevel)
protected function formatDate(\DateTimeInterface $value, int $nestingLevel): UTCDateTime
{
return new UTCDateTime((string) floor($value->format('U.u') * 1000));
}