Skip to content

Commit

Permalink
Extracted value formatting into it's own method
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Feb 4, 2017
1 parent 9fa848a commit 64d1610
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/AbstractLogglyLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,24 @@ private function processPlaceHolders(string $message, array $context): string
}

$replacements = [];
foreach ($context as $key => $val) {
if (is_null($val) || is_scalar($val) || (is_object($val) && method_exists($val, '__toString'))) {
$replacements['{'.$key.'}'] = $val;
continue;
}
foreach ($context as $key => $value) {
$replacements['{'.$key.'}'] = $this->formatValue($value);
}

if (is_object($val)) {
$replacements['{'.$key.'}'] = '[object '.get_class($val).']';
continue;
}
return strtr($message, $replacements);
}

$replacements['{'.$key.'}'] = '['.gettype($val).']';
private function formatValue($value)
{
if (is_null($value) || is_scalar($value) || (is_object($value) && method_exists($value, '__toString'))) {
return $value;
}

return strtr($message, $replacements);
if (is_object($value)) {
return '[object '.get_class($value).']';
}

return '['.gettype($value).']';
}

private function normalizeContext(array $context): array
Expand Down

0 comments on commit 64d1610

Please sign in to comment.